brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 208d693 Raw
55 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// constexpr auto operator->() const noexcept12//   requires contiguous_iterator<I>;13 14#include <iterator>15 16#include "test_macros.h"17#include "test_iterators.h"18 19template<class Iter>20concept ArrowEnabled = requires(Iter& iter) {21  iter.operator->();22};23 24constexpr bool test() {25  int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};26 27  {28    std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8);29    for (int i = 0; i < 8; ++i, ++iter)30      assert(iter.operator->() == buffer + i);31 32    static_assert(noexcept(iter.operator->()));33  }34  {35    const std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8);36    assert(iter.operator->() == buffer);37 38    static_assert(noexcept(iter.operator->()));39  }40 41  {42      static_assert( ArrowEnabled<std::counted_iterator<contiguous_iterator<int*>>>);43      static_assert(!ArrowEnabled<std::counted_iterator<random_access_iterator<int*>>>);44  }45 46  return true;47}48 49int main(int, char**) {50  test();51  static_assert(test());52 53  return 0;54}55