48 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// constexpr auto size() const requires (!same_as<Bound, unreachable_sentinel_t>);12 13#include <cassert>14#include <iterator>15#include <limits>16#include <ranges>17 18template <class T>19concept has_size = requires(T&& view) {20 { std::forward<T>(view).size() };21};22 23static_assert(has_size<std::ranges::repeat_view<int, int>>);24static_assert(!has_size<std::ranges::repeat_view<int>>);25static_assert(!has_size<std::ranges::repeat_view<int, std::unreachable_sentinel_t>>);26 27constexpr bool test() {28 {29 std::ranges::repeat_view<int, int> rv(10, 20);30 assert(rv.size() == 20);31 }32 33 {34 constexpr int int_max = std::numeric_limits<int>::max();35 std::ranges::repeat_view<int, int> rv(10, int_max);36 assert(rv.size() == int_max);37 }38 39 return true;40}41 42int main(int, char**) {43 test();44 static_assert(test());45 46 return 0;47}48