Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:41

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___RANGES_TAKE_WHILE_VIEW_H
0011 #define _LIBCPP___CXX03___RANGES_TAKE_WHILE_VIEW_H
0012 
0013 #include <__cxx03/__concepts/constructible.h>
0014 #include <__cxx03/__concepts/convertible_to.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__functional/bind_back.h>
0017 #include <__cxx03/__functional/invoke.h>
0018 #include <__cxx03/__iterator/concepts.h>
0019 #include <__cxx03/__memory/addressof.h>
0020 #include <__cxx03/__ranges/access.h>
0021 #include <__cxx03/__ranges/all.h>
0022 #include <__cxx03/__ranges/concepts.h>
0023 #include <__cxx03/__ranges/movable_box.h>
0024 #include <__cxx03/__ranges/range_adaptor.h>
0025 #include <__cxx03/__ranges/view_interface.h>
0026 #include <__cxx03/__type_traits/decay.h>
0027 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0028 #include <__cxx03/__type_traits/is_object.h>
0029 #include <__cxx03/__type_traits/maybe_const.h>
0030 #include <__cxx03/__utility/forward.h>
0031 #include <__cxx03/__utility/in_place.h>
0032 #include <__cxx03/__utility/move.h>
0033 
0034 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0035 #  pragma GCC system_header
0036 #endif
0037 
0038 _LIBCPP_PUSH_MACROS
0039 #include <__cxx03/__undef_macros>
0040 
0041 _LIBCPP_BEGIN_NAMESPACE_STD
0042 
0043 #if _LIBCPP_STD_VER >= 20
0044 
0045 namespace ranges {
0046 
0047 template <view _View, class _Pred>
0048   requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate<const _Pred, iterator_t<_View>>
0049 class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS take_while_view : public view_interface<take_while_view<_View, _Pred>> {
0050   template <bool>
0051   class __sentinel;
0052 
0053   _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
0054   _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;
0055 
0056 public:
0057   _LIBCPP_HIDE_FROM_ABI take_while_view()
0058     requires default_initializable<_View> && default_initializable<_Pred>
0059   = default;
0060 
0061   _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 take_while_view(_View __base, _Pred __pred)
0062       : __base_(std::move(__base)), __pred_(std::in_place, std::move(__pred)) {}
0063 
0064   _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
0065     requires copy_constructible<_View>
0066   {
0067     return __base_;
0068   }
0069 
0070   _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
0071 
0072   _LIBCPP_HIDE_FROM_ABI constexpr const _Pred& pred() const { return *__pred_; }
0073 
0074   _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
0075     requires(!__simple_view<_View>)
0076   {
0077     return ranges::begin(__base_);
0078   }
0079 
0080   _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
0081     requires range<const _View> && indirect_unary_predicate<const _Pred, iterator_t<const _View>>
0082   {
0083     return ranges::begin(__base_);
0084   }
0085 
0086   _LIBCPP_HIDE_FROM_ABI constexpr auto end()
0087     requires(!__simple_view<_View>)
0088   {
0089     return __sentinel</*_Const=*/false>(ranges::end(__base_), std::addressof(*__pred_));
0090   }
0091 
0092   _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
0093     requires range<const _View> && indirect_unary_predicate<const _Pred, iterator_t<const _View>>
0094   {
0095     return __sentinel</*_Const=*/true>(ranges::end(__base_), std::addressof(*__pred_));
0096   }
0097 };
0098 
0099 template <class _Range, class _Pred>
0100 take_while_view(_Range&&, _Pred) -> take_while_view<views::all_t<_Range>, _Pred>;
0101 
0102 template <view _View, class _Pred>
0103   requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate<const _Pred, iterator_t<_View>>
0104 template <bool _Const>
0105 class take_while_view<_View, _Pred>::__sentinel {
0106   using _Base = __maybe_const<_Const, _View>;
0107 
0108   sentinel_t<_Base> __end_ = sentinel_t<_Base>();
0109   const _Pred* __pred_     = nullptr;
0110 
0111   friend class __sentinel<!_Const>;
0112 
0113 public:
0114   _LIBCPP_HIDE_FROM_ABI __sentinel() = default;
0115 
0116   _LIBCPP_HIDE_FROM_ABI constexpr explicit __sentinel(sentinel_t<_Base> __end, const _Pred* __pred)
0117       : __end_(std::move(__end)), __pred_(__pred) {}
0118 
0119   _LIBCPP_HIDE_FROM_ABI constexpr __sentinel(__sentinel<!_Const> __s)
0120     requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
0121       : __end_(std::move(__s.__end_)), __pred_(__s.__pred_) {}
0122 
0123   _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Base> base() const { return __end_; }
0124 
0125   _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const iterator_t<_Base>& __x, const __sentinel& __y) {
0126     return __x == __y.__end_ || !std::invoke(*__y.__pred_, *__x);
0127   }
0128 
0129   template <bool _OtherConst = !_Const>
0130     requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
0131   _LIBCPP_HIDE_FROM_ABI friend constexpr bool
0132   operator==(const iterator_t<__maybe_const<_OtherConst, _View>>& __x, const __sentinel& __y) {
0133     return __x == __y.__end_ || !std::invoke(*__y.__pred_, *__x);
0134   }
0135 };
0136 
0137 namespace views {
0138 namespace __take_while {
0139 
0140 struct __fn {
0141   template <class _Range, class _Pred>
0142   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, _Pred&& __pred) const
0143       noexcept(noexcept(/**/ take_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))
0144           -> decltype(/*--*/ take_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))) {
0145     return /*-------------*/ take_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred));
0146   }
0147 
0148   template <class _Pred>
0149     requires constructible_from<decay_t<_Pred>, _Pred>
0150   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
0151       noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
0152     return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
0153   }
0154 };
0155 
0156 } // namespace __take_while
0157 
0158 inline namespace __cpo {
0159 inline constexpr auto take_while = __take_while::__fn{};
0160 } // namespace __cpo
0161 } // namespace views
0162 } // namespace ranges
0163 
0164 #endif // _LIBCPP_STD_VER >= 20
0165 
0166 _LIBCPP_END_NAMESPACE_STD
0167 
0168 _LIBCPP_POP_MACROS
0169 
0170 #endif // _LIBCPP___CXX03___RANGES_TAKE_WHILE_VIEW_H