[libcxx-commits] [clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 30 03:37:01 PST 2024
================
@@ -0,0 +1,626 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// 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_CONCAT_VIEW_H
+#define _LIBCPP___RANGES_CONCAT_VIEW_H
+
+#include <__algorithm/ranges_find_if.h>
+#include <__assert>
+#include <__concepts/common_reference_with.h>
+#include <__concepts/constructible.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/copyable.h>
+#include <__concepts/derived_from.h>
+#include <__concepts/equality_comparable.h>
+#include <__concepts/swappable.h>
+#include <__config>
+#include <__functional/bind_back.h>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/default_sentinel.h>
+#include <__iterator/distance.h>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iter_swap.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__memory/addressof.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/movable_box.h>
+#include <__ranges/non_propagating_cache.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/conditional.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_nothrow_constructible.h>
+#include <__type_traits/is_nothrow_convertible.h>
+#include <__type_traits/is_object.h>
+#include <__type_traits/make_unsigned.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/in_place.h>
+#include <__utility/move.h>
+#include <tuple>
+#include <variant>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+namespace ranges {
+
+template <class _T, class... _Tp>
+struct __extract_last : __extract_last<_Tp...> {};
+
+template <class _T>
+struct __extract_last<_T> {
+ using type = _T;
+};
+
+template <class _T, class... _Tp>
+struct __derived_from_pack {
+ constexpr static bool value =
+ __derived_from_pack<_T, typename __extract_last<_Tp...>::type>::value && __derived_from_pack<_Tp...>::value;
+};
+
+template <class _T, class _IterCategory>
+struct __derived_from_pack<_T, _IterCategory> {
+ constexpr static bool value = derived_from<_T, _IterCategory>;
+};
+
+template <class _View, class... _Views>
+struct __last_view : __last_view<_Views...> {};
+
+template <class _View>
+struct __last_view<_View> {
+ using type = _View;
+};
+
+template <class _Ref, class _RRef, class _It>
+concept __concat_indirectly_readable_impl = requires(const _It it) {
+ { *it } -> convertible_to<_Ref>;
+ { ranges::iter_move(it) } -> convertible_to<_RRef>;
+};
+
+template <class... _Rs>
+using __concat_reference_t = common_reference_t<range_reference_t<_Rs>...>;
+
+template <class... _Rs>
+using __concat_value_t = common_type_t<range_value_t<_Rs>...>;
+
+template <class... _Rs>
+using __concat_rvalue_reference_t = common_reference_t<range_rvalue_reference_t<_Rs>...>;
+
+template <class... _Rs>
+concept __concat_indirectly_readable =
+ common_reference_with<__concat_reference_t<_Rs...>&&, __concat_value_t<_Rs...>&> &&
+ common_reference_with<__concat_reference_t<_Rs...>&&, __concat_rvalue_reference_t<_Rs...>&&> &&
+ common_reference_with<__concat_rvalue_reference_t<_Rs...>&&, __concat_value_t<_Rs...> const&> &&
+ (__concat_indirectly_readable_impl<__concat_reference_t<_Rs...>,
+ __concat_rvalue_reference_t<_Rs...>,
+ iterator_t<_Rs>> &&
+ ...);
+
+template <class... _Rs>
+concept __concatable = requires {
+ typename __concat_reference_t<_Rs...>;
+ typename __concat_value_t<_Rs...>;
+ typename __concat_rvalue_reference_t<_Rs...>;
+} && __concat_indirectly_readable<_Rs...>;
+
+template <bool _Const, class... _Rs>
+concept __concat_is_random_access =
+ (random_access_range<__maybe_const<_Const, _Rs>> && ...) && (sized_range<__maybe_const<_Const, _Rs>> && ...);
+
+template <bool _Const, class... _Rs>
+concept __concat_is_bidirectional =
+ ((bidirectional_range<__maybe_const<_Const, _Rs>> && ...) && (common_range<__maybe_const<_Const, _Rs>> && ...));
+
+template <bool _Const, class... _Views>
+concept __all_forward = (forward_range<__maybe_const<_Const, _Views>> && ...);
+
+template <bool _Const, class... Ts>
+struct __apply_drop_first;
+
+template <bool _Const, class Head, class... Tail>
+struct __apply_drop_first<_Const, Head, Tail...> {
+ static constexpr bool value = (sized_range<__maybe_const<_Const, Tail>> && ...);
+};
+
+template <input_range... _Views>
+ requires(view<_Views> && ...) && (sizeof...(_Views) > 0) && __concatable<_Views...>
+class concat_view : public view_interface<concat_view<_Views...>> {
+ tuple<_Views...> views_;
----------------
frederick-vs-ja wrote:
Member names should be __ugly unless specified by the standard (ditto below).
```suggestion
tuple<_Views...> __views_;
```
https://github.com/llvm/llvm-project/pull/120920
More information about the libcxx-commits
mailing list