brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 8757d63 Raw
114 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++17, c++2010 11// <ranges>12 13// friend constexpr bool operator==(const iterator& x, const iterator& y);14// friend constexpr bool operator==(const iterator& x, default_sentinel_t);15 16#include <ranges>17 18#include <array>19#include <cassert>20#include <concepts>21#include <functional>22#include <utility>23 24#include "../types.h"25#include "test_iterators.h"26#include "test_macros.h"27 28template <class Iter, class Sent = sentinel_wrapper<Iter>>29constexpr void test() {30  using Underlying      = View<Iter, Sent>;31  using ChunkByView     = std::ranges::chunk_by_view<Underlying, std::ranges::less_equal>;32  using ChunkByIterator = std::ranges::iterator_t<ChunkByView>;33 34  auto make_chunk_by_view = [](auto& arr) {35    View view{Iter(arr.data()), Sent(Iter(arr.data() + arr.size()))};36    return ChunkByView(std::move(view), std::ranges::less_equal{});37  };38 39  // Test operator==40  {41    std::array array{0, 1, 2};42    ChunkByView view  = make_chunk_by_view(array);43    ChunkByIterator i = view.begin();44    ChunkByIterator j = view.begin();45 46    std::same_as<bool> decltype(auto) result = (i == j);47    assert(result);48    ++i;49    assert(!(i == j));50  }51 52  // Test synthesized operator!=53  {54    std::array array{0, 1, 2};55    ChunkByView view  = make_chunk_by_view(array);56    ChunkByIterator i = view.begin();57    ChunkByIterator j = view.begin();58 59    std::same_as<bool> decltype(auto) result = (i != j);60    assert(!result);61    ++i;62    assert(i != j);63  }64 65  // Test operator== with std::default_sentinel_t66  {67    std::array array{0, 1, 2};68    ChunkByView view  = make_chunk_by_view(array);69    ChunkByIterator i = view.begin();70 71    std::same_as<bool> decltype(auto) result = (i == std::default_sentinel);72    assert(!result);73    ++i;74    assert(i == std::default_sentinel);75  }76 77  // Test synthesized operator!= with std::default_sentinel_t78  {79    std::array array{0, 1, 2};80    ChunkByView view  = make_chunk_by_view(array);81    ChunkByIterator i = view.begin();82 83    std::same_as<bool> decltype(auto) result = (i != std::default_sentinel);84    assert(result);85    ++i;86    assert(!(i != std::default_sentinel));87  }88}89 90struct TestWithPair {91  template <class Iterator>92  constexpr void operator()() const {93    // Test with pair of iterators94    test<Iterator, Iterator>();95 96    // Test with iterator-sentinel pair97    test<Iterator>();98  }99};100 101constexpr bool tests() {102  TestWithPair tester;103  types::for_each(types::forward_iterator_list<int*>{}, tester);104  types::for_each(types::forward_iterator_list<int const*>{}, tester);105 106  return true;107}108 109int main(int, char**) {110  tests();111  static_assert(tests());112  return 0;113}114