1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // <copyable-box>::<copyable-box>()
13 
14 #include <ranges>
15 
16 #include <cassert>
17 #include <type_traits>
18 #include <utility> // in_place_t
19 
20 #include "types.h"
21 
22 template<class T>
23 using Box = std::ranges::__copyable_box<T>;
24 
25 struct NoDefault {
26   NoDefault() = delete;
27 };
28 static_assert(!std::is_default_constructible_v<Box<NoDefault>>);
29 
30 template<bool Noexcept>
31 struct DefaultNoexcept {
32   DefaultNoexcept() noexcept(Noexcept);
33 };
34 static_assert( std::is_nothrow_default_constructible_v<Box<DefaultNoexcept<true>>>);
35 static_assert(!std::is_nothrow_default_constructible_v<Box<DefaultNoexcept<false>>>);
36 
test()37 constexpr bool test() {
38   // check primary template
39   {
40     Box<CopyConstructible> box;
41     assert(box.__has_value());
42     assert((*box).value == CopyConstructible().value);
43   }
44 
45   // check optimization #1
46   {
47     Box<Copyable> box;
48     assert(box.__has_value());
49     assert((*box).value == Copyable().value);
50   }
51 
52   // check optimization #2
53   {
54     Box<NothrowCopyConstructible> box;
55     assert(box.__has_value());
56     assert((*box).value == NothrowCopyConstructible().value);
57   }
58 
59   return true;
60 }
61 
main(int,char **)62 int main(int, char**) {
63   assert(test());
64   static_assert(test());
65   return 0;
66 }
67