]> 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-2020 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20
21 #include <numeric>
22 #include <climits>
23 #include <testsuite_hooks.h>
24
25 const int* p = nullptr;
26 static_assert(std::is_same_v<decltype(std::midpoint(p, p)), decltype(p)>);
27 // This is a GNU extension:
28 static_assert(noexcept(std::midpoint(p, p)));
29
30 struct test_type { };
31 template<typename T> decltype(std::midpoint((T*)0, (T*)0)) try_midpoint(int);
32 template<typename T> test_type try_midpoint(...);
33 template<typename T> constexpr bool no_midpoint()
34 { return std::is_same_v<decltype(try_midpoint<T>()), test_type>; }
35
36 static_assert(no_midpoint<void>());
37 static_assert(no_midpoint<int()>());
38 static_assert(no_midpoint<int&>());
39 static_assert(no_midpoint<struct Incomplete>());
40
41 constexpr int ca[3] = {};
42 static_assert( std::midpoint(ca, ca+3) == ca+1 );
43
44 void
45 test01()
46 {
47 int a[4];
48 VERIFY( std::midpoint(a, a) == a );
49 VERIFY( std::midpoint(a, a+1) == a );
50 VERIFY( std::midpoint(a, a+2) == a+1 );
51 VERIFY( std::midpoint(a, a+3) == a+1 );
52 VERIFY( std::midpoint(a, a+4) == a+2 );
53 VERIFY( std::midpoint(a+1, a) == a+1 );
54 VERIFY( std::midpoint(a+2, a) == a+1 );
55 VERIFY( std::midpoint(a+3, a) == a+2 );
56 VERIFY( std::midpoint(a+4, a) == a+2 );
57 }
58
59 int main()
60 {
61 test01();
62 }