]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / optional / constexpr / relops / 2.cc
CommitLineData
52066eae 1// { dg-do compile { target c++14 } }
2b5ab1e4 2
99dee823 3// Copyright (C) 2013-2021 Free Software Foundation, Inc.
2b5ab1e4
MB
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
c7cbb4da 16// You should have received a copy of the GNU General Public License along
2b5ab1e4
MB
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20#include <experimental/optional>
21#include <testsuite_hooks.h>
22
23namespace ns
24{
25 struct value_type
26 {
27 int i;
28 const char* s;
29 };
30
31 constexpr bool
32 strcmp(const char* lhs, const char* rhs)
33 {
34 return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1));
35 }
36
37 constexpr bool
38 strrel(const char* lhs, const char* rhs)
39 {
40 return (*rhs && (!*lhs || (*lhs < *rhs)))
41 || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1));
42 }
43
44 constexpr bool
45 operator==(value_type const& lhs, value_type const& rhs)
46 { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
47
48 constexpr bool
49 operator!=(value_type const& lhs, value_type const& rhs)
50 { return !(lhs == rhs); }
51
52 constexpr bool
53 operator<(value_type const& lhs, value_type const& rhs)
54 { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
55
56} // namespace ns
57
58int main()
59{
60 using ns::value_type;
61 using O = std::experimental::optional<value_type>;
62
63 {
64 constexpr O o, p;
65 static_assert( !(o < p), "" );
66 static_assert( !(o > p), "" );
67 static_assert( o <= p, "" );
68 static_assert( o >= p, "" );
69 }
70
71 {
72 constexpr O o { value_type { 42, "forty-two" } }, p;
73 static_assert( !(o < p), "" );
74 static_assert( o > p, "" );
75 static_assert( !(o <= p), "" );
76 static_assert( o >= p, "" );
77 }
78
79 {
80 constexpr O o, p { value_type { 42, "forty-two" } };
81 static_assert( o < p, "" );
82 static_assert( !(o > p), "" );
83 static_assert( o <= p, "" );
84 static_assert( !(o >= p), "" );
85 }
86
87 {
88 constexpr O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } };
89 static_assert( o < p, "" );
90 static_assert( !(o > p), "" );
91 static_assert( o <= p, "" );
92 static_assert( !(o >= p), "" );
93 }
94
95 {
96 constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } };
97 static_assert( !(o < p), "" );
98 static_assert( o > p, "" );
99 static_assert( !(o <= p), "" );
100 static_assert( o >= p, "" );
101 }
102
103 {
104 constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } };
105 static_assert( !(o < p), "" );
106 static_assert( !(o > p), "" );
107 static_assert( o <= p, "" );
108 static_assert( o >= p, "" );
109 }
110}