]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / midpoint / pointer.cc
1 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
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-do run { target c++20 } }
19
20 #include <numeric>
21 #include <testsuite_hooks.h>
22
23 const int* p = nullptr;
24 static_assert(std::is_same_v<decltype(std::midpoint(p, p)), decltype(p)>);
25 // This is a GNU extension:
26 static_assert(noexcept(std::midpoint(p, p)));
27
28 struct test_type { };
29 template<typename T> decltype(std::midpoint((T*)0, (T*)0)) try_midpoint(int);
30 template<typename T> test_type try_midpoint(...);
31 template<typename T> constexpr bool no_midpoint()
32 { return std::is_same_v<decltype(try_midpoint<T>()), test_type>; }
33
34 static_assert(no_midpoint<void>());
35 static_assert(no_midpoint<int()>());
36 static_assert(no_midpoint<int&>());
37
38 constexpr int ca[3] = {};
39 static_assert( std::midpoint(ca, ca+3) == ca+1 );
40
41 void
42 test01()
43 {
44 int a[4];
45 VERIFY( std::midpoint(a, a) == a );
46 VERIFY( std::midpoint(a, a+1) == a );
47 VERIFY( std::midpoint(a, a+2) == a+1 );
48 VERIFY( std::midpoint(a, a+3) == a+1 );
49 VERIFY( std::midpoint(a, a+4) == a+2 );
50 VERIFY( std::midpoint(a+1, a) == a+1 );
51 VERIFY( std::midpoint(a+2, a) == a+1 );
52 VERIFY( std::midpoint(a+3, a) == a+2 );
53 VERIFY( std::midpoint(a+4, a) == a+2 );
54 }
55
56 int main()
57 {
58 test01();
59 }