]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/optional/constexpr/relops/3.cc
1 // { dg-do compile { target c++17 } }
3 // Copyright (C) 2013-2023 Free Software Foundation, Inc.
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)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 #include <testsuite_hooks.h>
32 strcmp(const char* lhs
, const char* rhs
)
34 return *lhs
== *rhs
&& (!*lhs
|| strcmp(lhs
+ 1, rhs
+ 1));
38 strrel(const char* lhs
, const char* rhs
)
40 return (*rhs
&& (!*lhs
|| (*lhs
< *rhs
)))
41 || ((*lhs
&& *rhs
&& !(*rhs
< *lhs
)) && strrel(lhs
+ 1, rhs
+ 1));
45 operator==(value_type
const& lhs
, value_type
const& rhs
)
46 { return (lhs
.i
== rhs
.i
) && strcmp(lhs
.s
, rhs
.s
); }
49 operator!=(value_type
const& lhs
, value_type
const& rhs
)
50 { return !(lhs
== rhs
); }
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
)); }
61 using O
= std::optional
<value_type
>;
63 constexpr value_type reference
{ 42, "forty-two" };
67 static_assert( !(o
== reference
), "" );
68 static_assert( !(reference
== o
), "" );
69 static_assert( o
!= reference
, "" );
70 static_assert( reference
!= o
, "" );
74 constexpr O o
{ value_type
{ 11, "eleventy" } };
75 static_assert( !(o
== reference
), "" );
76 static_assert( !(reference
== o
), "" );
77 static_assert( o
!= reference
, "" );
78 static_assert( reference
!= o
, "" );
82 constexpr O o
{ value_type
{ 42, "forty-two" } };
83 static_assert( o
== reference
, "" );
84 static_assert( reference
== o
, "" );
85 static_assert( !(o
!= reference
), "" );
86 static_assert( !(reference
!= o
), "" );