brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 9acc9b7 Raw
51 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <optional>12 13// [optional.nullops], comparison with nullopt14 15// template<class T>16//   constexpr strong_ordering operator<=>(const optional<T>&, nullopt_t) noexcept;17 18#include <cassert>19#include <compare>20#include <optional>21 22#include "test_comparisons.h"23 24constexpr bool test() {25  {26    std::optional<int> op;27    assert((std::nullopt <=> op) == std::strong_ordering::equal);28    assert(testOrder(std::nullopt, op, std::strong_ordering::equal));29    assert((op <=> std::nullopt) == std::strong_ordering::equal);30    assert(testOrder(op, std::nullopt, std::strong_ordering::equal));31  }32  {33    std::optional<int> op{1};34    assert((std::nullopt <=> op) == std::strong_ordering::less);35    assert(testOrder(std::nullopt, op, std::strong_ordering::less));36  }37  {38    std::optional<int> op{1};39    assert((op <=> std::nullopt) == std::strong_ordering::greater);40    assert(testOrder(op, std::nullopt, std::strong_ordering::greater));41  }42 43  return true;44}45 46int main(int, char**) {47  assert(test());48  static_assert(test());49  return 0;50}51