//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17 // // [optional.relops], relational operators // template U> // constexpr compare_three_way_result_t // operator<=>(const optional&, const optional&); #include #include #include #include "test_comparisons.h" constexpr bool test() { { std::optional op1; std::optional op2; assert((op1 <=> op2) == std::strong_ordering::equal); assert(testOrder(op1, op2, std::strong_ordering::equal)); } { std::optional op1{3}; std::optional op2{3}; assert((op1 <=> op1) == std::strong_ordering::equal); assert(testOrder(op1, op1, std::strong_ordering::equal)); assert((op1 <=> op2) == std::strong_ordering::equal); assert(testOrder(op1, op2, std::strong_ordering::equal)); assert((op2 <=> op1) == std::strong_ordering::equal); assert(testOrder(op2, op1, std::strong_ordering::equal)); } { std::optional op; std::optional op1{2}; std::optional op2{3}; assert((op <=> op2) == std::strong_ordering::less); assert(testOrder(op, op2, std::strong_ordering::less)); assert((op1 <=> op2) == std::strong_ordering::less); assert(testOrder(op1, op2, std::strong_ordering::less)); } { std::optional op; std::optional op1{3}; std::optional op2{2}; assert((op1 <=> op) == std::strong_ordering::greater); assert(testOrder(op1, op, std::strong_ordering::greater)); assert((op1 <=> op2) == std::strong_ordering::greater); assert(testOrder(op1, op2, std::strong_ordering::greater)); } return true; } int main(int, char**) { assert(test()); static_assert(test()); return 0; }