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