| 1 |
// { dg-do run { target c++17 } } |
| 2 |
|
| 3 |
// Copyright (C) 2017-2025 Free Software Foundation, Inc. |
| 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 |
|
| 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/>. |
| 19 |
|
| 20 |
#include <optional> |
| 21 |
#include <testsuite_hooks.h> |
| 22 |
#include <string> |
| 23 |
|
| 24 |
int main() |
| 25 |
{ |
| 26 |
std::optional<int> o = 42; |
| 27 |
std::optional<const int> o2 = 666; |
| 28 |
VERIFY(o == 42); |
| 29 |
VERIFY(o != 43); |
| 30 |
VERIFY(o < 43); |
| 31 |
VERIFY(o > 41); |
| 32 |
VERIFY(o <= 43); |
| 33 |
VERIFY(o >= 41); |
| 34 |
VERIFY(o2 == 666); |
| 35 |
VERIFY(o2 != 667); |
| 36 |
VERIFY(o2 < 667); |
| 37 |
VERIFY(o2 > 665); |
| 38 |
VERIFY(o2 <= 667); |
| 39 |
VERIFY(o2 >= 665); |
| 40 |
VERIFY(42 == o); |
| 41 |
VERIFY(43 != o); |
| 42 |
VERIFY(41< o); |
| 43 |
VERIFY(43 > o); |
| 44 |
VERIFY(41 <= o); |
| 45 |
VERIFY(43 >= o); |
| 46 |
VERIFY(666 == o2); |
| 47 |
VERIFY(667 != o2); |
| 48 |
VERIFY(665 < o2); |
| 49 |
VERIFY(667 > o2); |
| 50 |
VERIFY(665 <= o2); |
| 51 |
VERIFY(667 >= o2); |
| 52 |
std::optional<std::string> os = "jones"; |
| 53 |
VERIFY(os == "jones"); |
| 54 |
VERIFY(os != "bones"); |
| 55 |
VERIFY(os < "kones"); |
| 56 |
VERIFY(os > "hones"); |
| 57 |
VERIFY(os <= "kones"); |
| 58 |
VERIFY(os >= "hones"); |
| 59 |
VERIFY("jones" == os); |
| 60 |
VERIFY("bones" != os); |
| 61 |
VERIFY("hones" < os); |
| 62 |
VERIFY("kones" > os); |
| 63 |
VERIFY("hones" <= os); |
| 64 |
VERIFY("kones" >= os); |
| 65 |
std::optional<int> oi = 42; |
| 66 |
std::optional<long int> ol = 666; |
| 67 |
VERIFY(!(oi == ol)); |
| 68 |
VERIFY(!(ol == oi)); |
| 69 |
VERIFY(oi != ol); |
| 70 |
VERIFY(ol != oi); |
| 71 |
} |