brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 6cbc98a Raw
86 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// friend constexpr bool operator==(const outer-iterator& x, const outer-iterator& y)12//   requires forward_range<Base>;13//14// friend constexpr bool operator==(const outer-iterator& x, default_sentinel_t);15 16#include <ranges>17 18#include <concepts>19#include <string_view>20 21#include "../types.h"22 23#include "test_range.h"24 25constexpr bool test() {26  // Forward range supports both overloads of `operator==`.27  {28    // outer-iterator == outer-iterator29    {30      SplitViewForward v("abc def", " ");31      auto b = v.begin(), e = v.end();32 33      assert(b == b);34      assert(!(b != b));35 36      assert(e == e);37      assert(!(e != e));38 39      assert(!(b == e));40      assert(b != e);41    }42 43    // outer-iterator == default_sentinel44    {45      SplitViewForward v("abc def", " ");46      auto b = v.begin(), e = v.end();47 48      assert(!(b == std::default_sentinel));49      assert(b != std::default_sentinel);50      assert(e == std::default_sentinel);51      assert(!(e != std::default_sentinel));52    }53 54      // Default-constructed `outer-iterator`s compare equal.55      {56        OuterIterForward i1, i2;57        assert(i1 == i2);58        assert(!(i1 != i2));59      }60  }61 62  // Input range only supports comparing an `outer-iterator` to the default sentinel.63  {64    using namespace std::string_view_literals;65    SplitViewInput v("abc def"sv, ' ');66    auto b = v.begin();67    std::same_as<std::default_sentinel_t> decltype(auto) e = v.end();68 69    static_assert(!weakly_equality_comparable_with<decltype(b), decltype(b)>);70 71    assert(!(b == std::default_sentinel));72    assert(b != std::default_sentinel);73    assert(!(b == e));74    assert(b != e);75  }76 77  return true;78}79 80int main(int, char**) {81  test();82  static_assert(test());83 84  return 0;85}86