Back to home page

EIC code displayed by LXR

 
 

    


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

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_DROP_WHILE_VIEW_H
0011 #define _LIBCPP___CXX03___RANGES_DROP_WHILE_VIEW_H
0012 
0013 #include <__cxx03/__algorithm/ranges_find_if_not.h>
0014 #include <__cxx03/__assert>
0015 #include <__cxx03/__concepts/constructible.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/__functional/bind_back.h>
0018 #include <__cxx03/__functional/reference_wrapper.h>
0019 #include <__cxx03/__iterator/concepts.h>
0020 #include <__cxx03/__ranges/access.h>
0021 #include <__cxx03/__ranges/all.h>
0022 #include <__cxx03/__ranges/concepts.h>
0023 #include <__cxx03/__ranges/enable_borrowed_range.h>
0024 #include <__cxx03/__ranges/movable_box.h>
0025 #include <__cxx03/__ranges/non_propagating_cache.h>
0026 #include <__cxx03/__ranges/range_adaptor.h>
0027 #include <__cxx03/__ranges/view_interface.h>
0028 #include <__cxx03/__type_traits/conditional.h>
0029 #include <__cxx03/__type_traits/decay.h>
0030 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0031 #include <__cxx03/__type_traits/is_object.h>
0032 #include <__cxx03/__utility/forward.h>
0033 #include <__cxx03/__utility/in_place.h>
0034 #include <__cxx03/__utility/move.h>
0035 
0036 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0037 #  pragma GCC system_header
0038 #endif
0039 
0040 _LIBCPP_PUSH_MACROS
0041 #include <__cxx03/__undef_macros>
0042 
0043 _LIBCPP_BEGIN_NAMESPACE_STD
0044 
0045 #if _LIBCPP_STD_VER >= 20
0046 
0047 namespace ranges {
0048 
0049 template <view _View, class _Pred>
0050   requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate<const _Pred, iterator_t<_View>>
0051 class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS drop_while_view : public view_interface<drop_while_view<_View, _Pred>> {
0052 public:
0053   _LIBCPP_HIDE_FROM_ABI drop_while_view()
0054     requires default_initializable<_View> && default_initializable<_Pred>
0055   = default;
0056 
0057   _LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 drop_while_view(_View __base, _Pred __pred)
0058       : __base_(std::move(__base)), __pred_(std::in_place, std::move(__pred)) {}
0059 
0060   _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
0061     requires copy_constructible<_View>
0062   {
0063     return __base_;
0064   }
0065 
0066   _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }
0067 
0068   _LIBCPP_HIDE_FROM_ABI constexpr const _Pred& pred() const { return *__pred_; }
0069 
0070   _LIBCPP_HIDE_FROM_ABI constexpr auto begin() {
0071     // Note: this duplicates a check in `optional` but provides a better error message.
0072     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
0073         __pred_.__has_value(),
0074         "drop_while_view needs to have a non-empty predicate before calling begin() -- did a previous "
0075         "assignment to this drop_while_view fail?");
0076     if constexpr (_UseCache) {
0077       if (!__cached_begin_.__has_value()) {
0078         __cached_begin_.__emplace(ranges::find_if_not(__base_, std::cref(*__pred_)));
0079       }
0080       return *__cached_begin_;
0081     } else {
0082       return ranges::find_if_not(__base_, std::cref(*__pred_));
0083     }
0084   }
0085 
0086   _LIBCPP_HIDE_FROM_ABI constexpr auto end() { return ranges::end(__base_); }
0087 
0088 private:
0089   _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
0090   _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;
0091 
0092   static constexpr bool _UseCache = forward_range<_View>;
0093   using _Cache                    = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;
0094   _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();
0095 };
0096 
0097 template <class _View, class _Pred>
0098 inline constexpr bool enable_borrowed_range<drop_while_view<_View, _Pred>> = enable_borrowed_range<_View>;
0099 
0100 template <class _Range, class _Pred>
0101 drop_while_view(_Range&&, _Pred) -> drop_while_view<views::all_t<_Range>, _Pred>;
0102 
0103 namespace views {
0104 namespace __drop_while {
0105 
0106 struct __fn {
0107   template <class _Range, class _Pred>
0108   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, _Pred&& __pred) const
0109       noexcept(noexcept(/**/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))
0110           -> decltype(/*--*/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))) {
0111     return /*-------------*/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred));
0112   }
0113 
0114   template <class _Pred>
0115     requires constructible_from<decay_t<_Pred>, _Pred>
0116   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
0117       noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
0118     return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
0119   }
0120 };
0121 
0122 } // namespace __drop_while
0123 
0124 inline namespace __cpo {
0125 inline constexpr auto drop_while = __drop_while::__fn{};
0126 } // namespace __cpo
0127 } // namespace views
0128 } // namespace ranges
0129 
0130 #endif // _LIBCPP_STD_VER >= 20
0131 
0132 _LIBCPP_END_NAMESPACE_STD
0133 
0134 _LIBCPP_POP_MACROS
0135 
0136 #endif // _LIBCPP___CXX03___RANGES_DROP_WHILE_VIEW_H