]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/specialized_algorithms/construct_at/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / specialized_algorithms / construct_at / 1.cc
CommitLineData
a945c346 1// Copyright (C) 2019-2024 Free Software Foundation, Inc.
85f24114
JW
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
7dbb6913 18// { dg-do run { target c++20 } }
85f24114
JW
19
20#include <memory>
21#include <testsuite_hooks.h>
22
23template<typename T, typename... Args>
24 concept can_construct_at = requires(T* p, Args&&... args)
25 {
26 p = std::construct_at(p, std::forward<Args>(args)...);
27 };
28
29static_assert( can_construct_at<int> );
30static_assert( can_construct_at<int, int> );
31static_assert( !can_construct_at<int, int, int> );
32
33// Not required by C++20:
34static_assert( noexcept(std::construct_at(std::declval<int*>(), 1)) );
35
36void
37test01()
38{
39 int i = -1;
40 auto p = std::construct_at(&i);
41 VERIFY( p == &i );
42 VERIFY( i == 0 );
43 p = std::construct_at(&i, 42);
44 VERIFY( p == &i );
45 VERIFY( i == 42 );
46}
47
48struct X {
49 X(char&, void*) { }
50};
51
52static_assert( can_construct_at<X, char&, void*> );
53static_assert( !can_construct_at<X> );
54static_assert( !can_construct_at<X, char> );
55static_assert( !can_construct_at<X, char&, const void*> );
56
57static_assert( !noexcept(std::construct_at(std::declval<X*>(), std::declval<char&>(), std::declval<void*>())) );
58
59int
60main()
61{
62 test01();
63}