]>
Commit | Line | Data |
---|---|---|
99dee823 | 1 | // Copyright (C) 2020-2021 Free Software Foundation, Inc. |
42907ca9 PP |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do compile { target c++2a } } | |
20 | ||
21 | #include <ranges> | |
22 | ||
23 | using std::ranges::__detail::__box; | |
24 | ||
25 | using T = decltype([] { return 0; }); | |
26 | static_assert(std::is_empty_v<__box<T>>); | |
27 | static_assert(std::is_nothrow_copy_constructible_v<__box<T>>); | |
28 | static_assert(std::is_nothrow_move_constructible_v<__box<T>>); | |
29 | static_assert(std::is_nothrow_constructible_v<__box<T>, std::in_place_t>); | |
30 | static_assert(requires (__box<T> a) { | |
31 | a = a; | |
32 | a = std::move(a); | |
33 | a.operator*(); | |
34 | a.operator->(); | |
35 | a.has_value(); | |
36 | }); | |
37 | ||
38 | struct S | |
39 | { | |
40 | S(); | |
41 | ~S(); | |
42 | S(const S&); | |
43 | S(S&&); | |
44 | S& operator=(const S&); | |
45 | S& operator=(S&&); | |
46 | }; | |
47 | static_assert(std::is_empty_v<__box<S>>); | |
48 | static_assert(!std::is_nothrow_copy_constructible_v<__box<S>> | |
49 | && std::is_copy_constructible_v<__box<S>>); | |
50 | static_assert(!std::is_nothrow_move_constructible_v<__box<S>> | |
51 | && std::is_move_constructible_v<__box<S>>); | |
52 | static_assert(!std::is_nothrow_constructible_v<__box<S>, std::in_place_t> | |
53 | && std::is_constructible_v<__box<S>, std::in_place_t>); | |
54 | static_assert(requires (__box<S> a) { | |
55 | a = a; | |
56 | a = std::move(a); | |
57 | a.operator*(); | |
58 | a.operator->(); | |
59 | a.has_value(); | |
60 | }); | |
61 | ||
62 | using U = decltype([i=0] { return 0; }); | |
63 | static_assert(!std::is_empty_v<__box<U>>); | |
64 | static_assert(std::is_nothrow_copy_constructible_v<__box<U>>); | |
65 | static_assert(std::is_nothrow_move_constructible_v<__box<U>>); | |
66 | static_assert(!std::is_nothrow_constructible_v<__box<U>, std::in_place_t>); | |
67 | static_assert(requires (__box<U> a) { | |
68 | a = a; | |
69 | a = std::move(a); | |
70 | a.operator*(); | |
71 | a.operator->(); | |
72 | a.has_value(); | |
73 | }); | |
f3ced677 PP |
74 | |
75 | constexpr bool | |
76 | test01() | |
77 | { | |
78 | // Verify the default constructor value-initializes the underlying object. | |
79 | __box<int> x; | |
80 | __glibcxx_assert(*x == 0); | |
81 | return true; | |
82 | } | |
83 | static_assert(test01()); |