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