forked from OSchip/llvm-project
[libc++] Add range_size_t
Differential Revision: https://reviews.llvm.org/D106708
This commit is contained in:
parent
77c5e6ba90
commit
fbaf7f0bc7
|
@ -103,10 +103,10 @@ Section,Description,Dependencies,Assignee,Complete
|
|||
| `ranges::iterator_t <https://llvm.org/D100255>`_
|
||||
| `ranges::sentinel_t <https://llvm.org/D100269>`_
|
||||
| `ranges::range_difference_t <https://llvm.org/D100269>`_
|
||||
| ranges::range_size_t
|
||||
| `ranges::range_size_t <https://llvm.org/D106708>`_
|
||||
| `ranges::range_value_t <https://llvm.org/D100269>`_
|
||||
| `ranges::range_reference_t <https://llvm.org/D100269>`_
|
||||
| `ranges::range_rvalue_reference_t <https://llvm.org/D100269>`_",[range.access],Christopher Di Bella,In progress
|
||||
| `ranges::range_rvalue_reference_t <https://llvm.org/D100269>`_",[range.access],Christopher Di Bella,✅
|
||||
`[range.sized] <http://wg21.link/range.sized>`_,"| `ranges::sized_range <https://llvm.org/D102434>`_
|
||||
| `ranges::disable_sized_range <https://llvm.org/D102434>`_","| [range.primitives]
|
||||
| [range.range]",Christopher Di Bella,✅
|
||||
|
|
|
|
@ -69,6 +69,9 @@ namespace ranges {
|
|||
template <class _Tp>
|
||||
concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
|
||||
|
||||
template<sized_range _Rp>
|
||||
using range_size_t = decltype(ranges::size(declval<_Rp&>()));
|
||||
|
||||
// `disable_sized_range` defined in `<__ranges/size.h>`
|
||||
|
||||
// [range.view], views
|
||||
|
|
|
@ -36,13 +36,13 @@ namespace std::ranges {
|
|||
inline constexpr bool enable_borrowed_range = false;
|
||||
|
||||
template<class T>
|
||||
using iterator_t = decltype(ranges::begin(declval<T&>()));
|
||||
template<class T>
|
||||
using iterator_t = decltype(ranges::begin(declval<T&>()));
|
||||
using iterator_t = decltype(ranges::begin(declval<R&>()));
|
||||
template<range R>
|
||||
using sentinel_t = decltype(ranges::end(declval<R&>()));
|
||||
template<range R>
|
||||
using range_difference_t = iter_difference_t<iterator_t<R>>;
|
||||
template<sized_range R>
|
||||
using range_size_t = decltype(ranges::size(declval<R&>()));
|
||||
template<range R>
|
||||
using range_value_t = iter_value_t<iterator_t<R>>;
|
||||
template<range R>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14, c++17
|
||||
// UNSUPPORTED: libcpp-no-concepts
|
||||
// UNSUPPORTED: gcc-10
|
||||
|
||||
// template<sized_range R>
|
||||
// using range_size_t = decltype(ranges::size(declval<R&>()));
|
||||
|
||||
#include <ranges>
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template<class T>
|
||||
concept has_range_size_t = requires { typename std::ranges::range_size_t<T>; };
|
||||
|
||||
struct A { int *begin(); int *end(); short size(); };
|
||||
static_assert(std::same_as<std::ranges::range_size_t<A>, short>);
|
||||
static_assert(std::same_as<std::ranges::range_size_t<A&>, short>);
|
||||
static_assert(std::same_as<std::ranges::range_size_t<A&&>, short>);
|
||||
static_assert(!has_range_size_t<const A>);
|
||||
static_assert(!has_range_size_t<const A&>);
|
||||
static_assert(!has_range_size_t<const A&&>);
|
||||
|
||||
struct B { int *begin(); int *end(); };
|
||||
static_assert(std::same_as<std::ranges::range_size_t<B>, std::size_t>);
|
||||
static_assert(std::same_as<std::ranges::range_size_t<B&>, std::size_t>);
|
||||
static_assert(std::same_as<std::ranges::range_size_t<B&&>, std::size_t>);
|
||||
static_assert(!has_range_size_t<const B>);
|
||||
static_assert(!has_range_size_t<const B&>);
|
||||
static_assert(!has_range_size_t<const B&&>);
|
||||
|
||||
struct C { bidirectional_iterator<int*> begin(); bidirectional_iterator<int*> end(); };
|
||||
static_assert(!has_range_size_t<C>);
|
Loading…
Reference in New Issue