brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 6740e3b Raw
52 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 size() requires sized_range<V>12// constexpr auto size() const requires sized_range<const V>13 14#include <ranges>15#include <cassert>16 17#include "test_iterators.h"18#include "types.h"19 20template<class View>21concept SizeEnabled = requires(View v) { v.size(); };22 23constexpr bool test() {24  int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};25 26  {27    static_assert( SizeEnabled<std::ranges::common_view<SizedForwardView> const&>);28    static_assert(!SizeEnabled<std::ranges::common_view<CopyableView> const&>);29  }30 31  {32    SizedForwardView view{buf, buf + 8};33    std::ranges::common_view<SizedForwardView> common(view);34    assert(common.size() == 8);35  }36 37  {38    SizedForwardView view{buf, buf + 8};39    std::ranges::common_view<SizedForwardView> const common(view);40    assert(common.size() == 8);41  }42 43  return true;44}45 46int main(int, char**) {47  test();48  static_assert(test());49 50  return 0;51}52