2020-11-25 01:08:02 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-11-25 01:08:02 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_RANGES
|
|
|
|
#define _LIBCPP_RANGES
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#include <compare> // see [compare.syn]
|
|
|
|
#include <initializer_list> // see [initializer.list.syn]
|
|
|
|
#include <iterator> // see [iterator.synopsis]
|
|
|
|
|
|
|
|
namespace std::ranges {
|
2021-04-11 13:08:32 +08:00
|
|
|
inline namespace unspecified {
|
|
|
|
// [range.access], range access
|
|
|
|
inline constexpr unspecified begin = unspecified;
|
|
|
|
inline constexpr unspecified end = unspecified;
|
|
|
|
inline constexpr unspecified cbegin = unspecified;
|
|
|
|
inline constexpr unspecified cend = unspecified;
|
2021-04-23 00:29:02 +08:00
|
|
|
|
|
|
|
inline constexpr unspecified size = unspecified;
|
2021-04-24 02:23:22 +08:00
|
|
|
inline constexpr unspecified ssize = unspecified;
|
2021-04-11 13:08:32 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 01:08:02 +08:00
|
|
|
// [range.range], ranges
|
2021-04-12 01:40:30 +08:00
|
|
|
template<class T>
|
|
|
|
concept range = see below;
|
|
|
|
|
2020-11-25 01:08:02 +08:00
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range = false;
|
2021-04-11 13:08:32 +08:00
|
|
|
|
|
|
|
template<class T>
|
2021-11-21 08:15:00 +08:00
|
|
|
using iterator_t = decltype(ranges::begin(declval<T&>()));
|
2021-04-12 01:40:30 +08:00
|
|
|
template<range R>
|
|
|
|
using sentinel_t = decltype(ranges::end(declval<R&>()));
|
|
|
|
template<range R>
|
|
|
|
using range_difference_t = iter_difference_t<iterator_t<R>>;
|
2021-07-24 04:46:31 +08:00
|
|
|
template<sized_range R>
|
|
|
|
using range_size_t = decltype(ranges::size(declval<R&>()));
|
2021-04-12 01:40:30 +08:00
|
|
|
template<range R>
|
|
|
|
using range_value_t = iter_value_t<iterator_t<R>>;
|
|
|
|
template<range R>
|
|
|
|
using range_reference_t = iter_reference_t<iterator_t<R>>;
|
|
|
|
template<range R>
|
|
|
|
using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
|
|
|
|
|
2021-07-12 21:55:00 +08:00
|
|
|
// [range.sized], sized ranges
|
2021-05-14 03:34:06 +08:00
|
|
|
template<class>
|
|
|
|
inline constexpr bool disable_sized_range = false;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept sized_range = ...;
|
|
|
|
|
2021-04-29 03:22:11 +08:00
|
|
|
// [range.view], views
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_view = ...;
|
|
|
|
|
|
|
|
struct view_base { };
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept view = ...;
|
|
|
|
|
2021-04-12 01:40:30 +08:00
|
|
|
// [range.refinements], other range refinements
|
2021-07-24 03:26:23 +08:00
|
|
|
template<class R, class T>
|
|
|
|
concept output_range = see below;
|
|
|
|
|
2021-04-12 03:04:52 +08:00
|
|
|
template<class T>
|
|
|
|
concept input_range = see below;
|
|
|
|
|
2021-04-12 06:11:03 +08:00
|
|
|
template<class T>
|
|
|
|
concept forward_range = see below;
|
|
|
|
|
2021-04-12 09:16:45 +08:00
|
|
|
template<class T>
|
|
|
|
concept bidirectional_range = see below;
|
|
|
|
|
2021-06-15 04:08:15 +08:00
|
|
|
template<class T>
|
|
|
|
concept random_access_range = see below;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept contiguous_range = see below;
|
|
|
|
|
2021-04-12 01:40:30 +08:00
|
|
|
template <class _Tp>
|
|
|
|
concept common_range = see below;
|
2021-05-01 06:24:28 +08:00
|
|
|
|
2021-07-12 21:55:00 +08:00
|
|
|
template<class T>
|
|
|
|
concept viewable_range = see below;
|
|
|
|
|
2021-05-01 06:24:28 +08:00
|
|
|
// [view.interface], class template view_interface
|
|
|
|
template<class D>
|
|
|
|
requires is_class_v<D> && same_as<D, remove_cv_t<D>>
|
|
|
|
class view_interface;
|
2021-05-27 05:25:02 +08:00
|
|
|
|
2021-07-17 09:35:42 +08:00
|
|
|
// [range.subrange], sub-ranges
|
|
|
|
enum class subrange_kind : bool { unsized, sized };
|
|
|
|
|
|
|
|
template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
|
|
|
|
requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
|
|
|
|
class subrange;
|
|
|
|
|
|
|
|
template<class I, class S, subrange_kind K>
|
|
|
|
inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
|
|
|
|
|
2021-07-09 05:01:19 +08:00
|
|
|
// [range.dangling], dangling iterator handling
|
|
|
|
struct dangling;
|
|
|
|
|
|
|
|
template<range R>
|
|
|
|
using borrowed_iterator_t = see below;
|
|
|
|
|
|
|
|
template<range R>
|
|
|
|
using borrowed_subrange_t = see below;
|
|
|
|
|
2021-05-27 05:25:02 +08:00
|
|
|
// [range.empty], empty view
|
|
|
|
template<class T>
|
|
|
|
requires is_object_v<T>
|
|
|
|
class empty_view;
|
2021-06-25 02:05:50 +08:00
|
|
|
|
2022-04-06 00:17:02 +08:00
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
|
|
|
|
|
|
|
|
namespace views {
|
|
|
|
template<class T>
|
|
|
|
inline constexpr empty_view<T> empty{};
|
|
|
|
}
|
|
|
|
|
2021-07-12 21:55:00 +08:00
|
|
|
// [range.all], all view
|
|
|
|
namespace views {
|
|
|
|
inline constexpr unspecified all = unspecified;
|
|
|
|
|
|
|
|
template<viewable_range R>
|
|
|
|
using all_t = decltype(all(declval<R>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<range R>
|
|
|
|
requires is_object_v<R>
|
|
|
|
class ref_view;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
|
|
|
|
|
2022-01-09 22:00:35 +08:00
|
|
|
template<range R>
|
|
|
|
requires see below
|
|
|
|
class owning_view;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
|
|
|
|
|
2021-07-15 05:01:25 +08:00
|
|
|
// [range.filter], filter view
|
|
|
|
template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
|
|
|
|
requires view<V> && is_object_v<Pred>
|
|
|
|
class filter_view;
|
|
|
|
|
|
|
|
namespace views {
|
|
|
|
inline constexpr unspecified filter = unspecified;
|
|
|
|
}
|
|
|
|
|
2021-06-25 02:05:50 +08:00
|
|
|
// [range.drop], drop view
|
|
|
|
template<view V>
|
|
|
|
class drop_view;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
|
2021-07-10 01:12:16 +08:00
|
|
|
|
|
|
|
// [range.transform], transform view
|
|
|
|
template<input_range V, copy_constructible F>
|
|
|
|
requires view<V> && is_object_v<F> &&
|
|
|
|
regular_invocable<F&, range_reference_t<V>> &&
|
|
|
|
can-reference<invoke_result_t<F&, range_reference_t<V>>>
|
|
|
|
class transform_view;
|
|
|
|
|
2021-07-28 06:44:33 +08:00
|
|
|
// [range.counted], counted view
|
|
|
|
namespace views { inline constexpr unspecified counted = unspecified; }
|
|
|
|
|
2021-07-10 01:09:31 +08:00
|
|
|
// [range.common], common view
|
|
|
|
template<view V>
|
|
|
|
requires (!common_range<V> && copyable<iterator_t<V>>)
|
|
|
|
class common_view;
|
|
|
|
|
2021-07-29 08:11:04 +08:00
|
|
|
// [range.reverse], reverse view
|
|
|
|
template<view V>
|
|
|
|
requires bidirectional_range<V>
|
|
|
|
class reverse_view;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
|
|
|
|
|
2021-07-10 01:09:31 +08:00
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
|
2021-05-26 23:59:14 +08:00
|
|
|
|
|
|
|
// [range.take], take view
|
|
|
|
template<view> class take_view;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
|
2021-07-27 08:27:40 +08:00
|
|
|
|
|
|
|
template<copy_constructible T>
|
|
|
|
requires is_object_v<T>
|
|
|
|
class single_view;
|
2021-08-04 04:05:20 +08:00
|
|
|
|
|
|
|
template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
|
|
|
|
requires weakly-equality-comparable-with<W, Bound> && copyable<W>
|
|
|
|
class iota_view;
|
|
|
|
|
|
|
|
template<class W, class Bound>
|
|
|
|
inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
|
2021-08-07 06:33:46 +08:00
|
|
|
|
|
|
|
// [range.join], join view
|
|
|
|
template<input_range V>
|
|
|
|
requires view<V> && input_range<range_reference_t<V>>
|
|
|
|
class join_view;
|
2022-04-13 13:27:07 +08:00
|
|
|
|
|
|
|
// [range.lazy.split], lazy split view
|
|
|
|
template<class R>
|
|
|
|
concept tiny-range = see below; // exposition only
|
|
|
|
|
|
|
|
template<input_range V, forward_range Pattern>
|
|
|
|
requires view<V> && view<Pattern> &&
|
|
|
|
indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
|
|
|
|
(forward_range<V> || tiny-range<Pattern>)
|
|
|
|
class lazy_split_view;
|
|
|
|
|
|
|
|
namespace views {
|
|
|
|
inline constexpr unspecified lazy_split = unspecified;
|
|
|
|
}
|
2022-04-25 18:18:54 +08:00
|
|
|
|
|
|
|
// [range.zip], zip view
|
|
|
|
template<input_range... Views>
|
|
|
|
requires (view<Views> && ...) && (sizeof...(Views) > 0)
|
|
|
|
class zip_view; // C++2b
|
|
|
|
|
|
|
|
template<class... Views>
|
|
|
|
inline constexpr bool enable_borrowed_range<zip_view<Views...>> = // C++2b
|
|
|
|
(enable_borrowed_range<Views> && ...);
|
|
|
|
|
|
|
|
namespace views { inline constexpr unspecified zip = unspecified; } // C++2b
|
2020-11-25 01:08:02 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 14:58:12 +08:00
|
|
|
namespace std {
|
|
|
|
namespace views = ranges::views;
|
|
|
|
|
|
|
|
template<class T> struct tuple_size;
|
|
|
|
template<size_t I, class T> struct tuple_element;
|
|
|
|
|
|
|
|
template<class I, class S, ranges::subrange_kind K>
|
|
|
|
struct tuple_size<ranges::subrange<I, S, K>>
|
|
|
|
: integral_constant<size_t, 2> {};
|
|
|
|
|
|
|
|
template<class I, class S, ranges::subrange_kind K>
|
|
|
|
struct tuple_element<0, ranges::subrange<I, S, K>> {
|
|
|
|
using type = I;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class I, class S, ranges::subrange_kind K>
|
|
|
|
struct tuple_element<1, ranges::subrange<I, S, K>> {
|
|
|
|
using type = S;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class I, class S, ranges::subrange_kind K>
|
|
|
|
struct tuple_element<0, const ranges::subrange<I, S, K>> {
|
|
|
|
using type = I;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class I, class S, ranges::subrange_kind K>
|
|
|
|
struct tuple_element<1, const ranges::subrange<I, S, K>> {
|
|
|
|
using type = S;
|
|
|
|
};
|
|
|
|
}
|
2020-11-25 01:08:02 +08:00
|
|
|
*/
|
|
|
|
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2020-11-25 01:08:02 +08:00
|
|
|
#include <__config>
|
2021-04-11 13:08:32 +08:00
|
|
|
#include <__ranges/access.h>
|
2021-05-07 06:31:45 +08:00
|
|
|
#include <__ranges/all.h>
|
2021-07-10 01:09:31 +08:00
|
|
|
#include <__ranges/common_view.h>
|
2021-04-12 01:40:30 +08:00
|
|
|
#include <__ranges/concepts.h>
|
2021-08-27 02:18:03 +08:00
|
|
|
#include <__ranges/counted.h>
|
2021-07-09 05:01:19 +08:00
|
|
|
#include <__ranges/dangling.h>
|
2021-04-24 06:22:18 +08:00
|
|
|
#include <__ranges/data.h>
|
2021-05-07 08:39:53 +08:00
|
|
|
#include <__ranges/drop_view.h>
|
2021-08-27 02:18:03 +08:00
|
|
|
#include <__ranges/empty.h>
|
2022-01-07 22:45:05 +08:00
|
|
|
#include <__ranges/empty_view.h>
|
2020-11-25 01:08:02 +08:00
|
|
|
#include <__ranges/enable_borrowed_range.h>
|
2021-06-11 02:40:21 +08:00
|
|
|
#include <__ranges/enable_view.h>
|
2021-07-15 05:01:25 +08:00
|
|
|
#include <__ranges/filter_view.h>
|
2021-08-04 04:05:20 +08:00
|
|
|
#include <__ranges/iota_view.h>
|
2021-08-07 06:33:46 +08:00
|
|
|
#include <__ranges/join_view.h>
|
2022-04-13 13:27:07 +08:00
|
|
|
#include <__ranges/lazy_split_view.h>
|
2022-02-14 19:29:18 +08:00
|
|
|
#include <__ranges/rbegin.h>
|
2021-05-07 04:19:13 +08:00
|
|
|
#include <__ranges/ref_view.h>
|
2022-02-14 19:29:18 +08:00
|
|
|
#include <__ranges/rend.h>
|
2021-07-29 08:11:04 +08:00
|
|
|
#include <__ranges/reverse_view.h>
|
2021-07-27 08:27:40 +08:00
|
|
|
#include <__ranges/single_view.h>
|
2021-04-23 00:29:02 +08:00
|
|
|
#include <__ranges/size.h>
|
2021-05-04 05:37:42 +08:00
|
|
|
#include <__ranges/subrange.h>
|
2021-07-27 08:27:40 +08:00
|
|
|
#include <__ranges/take_view.h>
|
2021-07-10 01:12:16 +08:00
|
|
|
#include <__ranges/transform_view.h>
|
2021-05-01 06:24:28 +08:00
|
|
|
#include <__ranges/view_interface.h>
|
2022-02-03 01:23:51 +08:00
|
|
|
#include <__ranges/views.h>
|
2022-04-25 18:18:54 +08:00
|
|
|
#include <__ranges/zip_view.h>
|
2022-03-07 23:31:33 +08:00
|
|
|
#include <__tuple> // TODO: <ranges> has to export std::tuple_size. Replace this, once <tuple> is granularized.
|
2020-11-25 01:08:02 +08:00
|
|
|
#include <compare> // Required by the standard.
|
|
|
|
#include <initializer_list> // Required by the standard.
|
|
|
|
#include <iterator> // Required by the standard.
|
|
|
|
#include <type_traits>
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#include <version>
|
2021-07-25 15:18:53 +08:00
|
|
|
|
2020-11-25 01:08:02 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2020-11-25 01:08:02 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // _LIBCPP_RANGES
|