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 11 // <copyable-box>::<copyable-box>() 12 13 #include <ranges> 14 15 #include <cassert> 16 #include <type_traits> 17 #include <utility> // in_place_t 18 19 #include "types.h" 20 21 template<class T> 22 using Box = std::ranges::__copyable_box<T>; 23 24 struct NoDefault { 25 NoDefault() = delete; 26 }; 27 static_assert(!std::is_default_constructible_v<Box<NoDefault>>); 28 29 template<bool Noexcept> 30 struct DefaultNoexcept { 31 DefaultNoexcept() noexcept(Noexcept); 32 }; 33 static_assert( std::is_nothrow_default_constructible_v<Box<DefaultNoexcept<true>>>); 34 static_assert(!std::is_nothrow_default_constructible_v<Box<DefaultNoexcept<false>>>); 35 test()36constexpr bool test() { 37 // check primary template 38 { 39 Box<CopyConstructible> box; 40 assert(box.__has_value()); 41 assert((*box).value == CopyConstructible().value); 42 } 43 44 // check optimization #1 45 { 46 Box<Copyable> box; 47 assert(box.__has_value()); 48 assert((*box).value == Copyable().value); 49 } 50 51 // check optimization #2 52 { 53 Box<NothrowCopyConstructible> box; 54 assert(box.__has_value()); 55 assert((*box).value == NothrowCopyConstructible().value); 56 } 57 58 return true; 59 } 60 main(int,char **)61int main(int, char**) { 62 assert(test()); 63 static_assert(test()); 64 return 0; 65 } 66