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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17
10
11// template<sized_range R>
12// using range_size_t = decltype(ranges::size(declval<R&>()));
13
14#include <ranges>
15#include <concepts>
16#include <cstddef>
17
18#include "test_iterators.h"
19
20template<class T>
21concept has_range_size_t = requires { typename std::ranges::range_size_t<T>; };
22
23struct A { int *begin(); int *end(); short size(); };
24static_assert(std::same_as<std::ranges::range_size_t<A>, short>);
25static_assert(std::same_as<std::ranges::range_size_t<A&>, short>);
26static_assert(std::same_as<std::ranges::range_size_t<A&&>, short>);
27static_assert(!has_range_size_t<const A>);
28static_assert(!has_range_size_t<const A&>);
29static_assert(!has_range_size_t<const A&&>);
30
31struct B { int *begin(); int *end(); };
32static_assert(std::same_as<std::ranges::range_size_t<B>, std::size_t>);
33static_assert(std::same_as<std::ranges::range_size_t<B&>, std::size_t>);
34static_assert(std::same_as<std::ranges::range_size_t<B&&>, std::size_t>);
35static_assert(!has_range_size_t<const B>);
36static_assert(!has_range_size_t<const B&>);
37static_assert(!has_range_size_t<const B&&>);
38
39struct C { bidirectional_iterator<int*> begin(); bidirectional_iterator<int*> end(); };
40static_assert(!has_range_size_t<C>);
41

source code of libcxx/test/std/ranges/range.req/range.range/range_size_t.compile.pass.cpp