]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/std/ranges/adaptors/detail/semiregular_box.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / adaptors / detail / semiregular_box.cc
CommitLineData
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
23using std::ranges::__detail::__box;
24
25using T = decltype([] { return 0; });
26static_assert(std::is_empty_v<__box<T>>);
27static_assert(std::is_nothrow_copy_constructible_v<__box<T>>);
28static_assert(std::is_nothrow_move_constructible_v<__box<T>>);
29static_assert(std::is_nothrow_constructible_v<__box<T>, std::in_place_t>);
30static_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
38struct S
39{
40 S();
41 ~S();
42 S(const S&);
43 S(S&&);
44 S& operator=(const S&);
45 S& operator=(S&&);
46};
47static_assert(std::is_empty_v<__box<S>>);
48static_assert(!std::is_nothrow_copy_constructible_v<__box<S>>
49 && std::is_copy_constructible_v<__box<S>>);
50static_assert(!std::is_nothrow_move_constructible_v<__box<S>>
51 && std::is_move_constructible_v<__box<S>>);
52static_assert(!std::is_nothrow_constructible_v<__box<S>, std::in_place_t>
53 && std::is_constructible_v<__box<S>, std::in_place_t>);
54static_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
62using U = decltype([i=0] { return 0; });
63static_assert(!std::is_empty_v<__box<U>>);
64static_assert(std::is_nothrow_copy_constructible_v<__box<U>>);
65static_assert(std::is_nothrow_move_constructible_v<__box<U>>);
66static_assert(!std::is_nothrow_constructible_v<__box<U>, std::in_place_t>);
67static_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
75constexpr bool
76test01()
77{
78 // Verify the default constructor value-initializes the underlying object.
79 __box<int> x;
80 __glibcxx_assert(*x == 0);
81 return true;
82}
83static_assert(test01());