Path: blob/main/contrib/llvm-project/libcxx/include/__ranges/drop_while_view.h
35236 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___RANGES_DROP_WHILE_VIEW_H10#define _LIBCPP___RANGES_DROP_WHILE_VIEW_H1112#include <__algorithm/ranges_find_if_not.h>13#include <__assert>14#include <__concepts/constructible.h>15#include <__config>16#include <__functional/bind_back.h>17#include <__functional/reference_wrapper.h>18#include <__iterator/concepts.h>19#include <__ranges/access.h>20#include <__ranges/all.h>21#include <__ranges/concepts.h>22#include <__ranges/enable_borrowed_range.h>23#include <__ranges/movable_box.h>24#include <__ranges/non_propagating_cache.h>25#include <__ranges/range_adaptor.h>26#include <__ranges/view_interface.h>27#include <__type_traits/conditional.h>28#include <__type_traits/decay.h>29#include <__type_traits/is_nothrow_constructible.h>30#include <__type_traits/is_object.h>31#include <__utility/forward.h>32#include <__utility/in_place.h>33#include <__utility/move.h>3435#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)36# pragma GCC system_header37#endif3839_LIBCPP_PUSH_MACROS40#include <__undef_macros>4142_LIBCPP_BEGIN_NAMESPACE_STD4344#if _LIBCPP_STD_VER >= 204546namespace ranges {4748template <view _View, class _Pred>49requires input_range<_View> && is_object_v<_Pred> && indirect_unary_predicate<const _Pred, iterator_t<_View>>50class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS drop_while_view : public view_interface<drop_while_view<_View, _Pred>> {51public:52_LIBCPP_HIDE_FROM_ABI drop_while_view()53requires default_initializable<_View> && default_initializable<_Pred>54= default;5556_LIBCPP_HIDE_FROM_ABI constexpr _LIBCPP_EXPLICIT_SINCE_CXX23 drop_while_view(_View __base, _Pred __pred)57: __base_(std::move(__base)), __pred_(std::in_place, std::move(__pred)) {}5859_LIBCPP_HIDE_FROM_ABI constexpr _View base() const&60requires copy_constructible<_View>61{62return __base_;63}6465_LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); }6667_LIBCPP_HIDE_FROM_ABI constexpr const _Pred& pred() const { return *__pred_; }6869_LIBCPP_HIDE_FROM_ABI constexpr auto begin() {70// Note: this duplicates a check in `optional` but provides a better error message.71_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(72__pred_.__has_value(),73"drop_while_view needs to have a non-empty predicate before calling begin() -- did a previous "74"assignment to this drop_while_view fail?");75if constexpr (_UseCache) {76if (!__cached_begin_.__has_value()) {77__cached_begin_.__emplace(ranges::find_if_not(__base_, std::cref(*__pred_)));78}79return *__cached_begin_;80} else {81return ranges::find_if_not(__base_, std::cref(*__pred_));82}83}8485_LIBCPP_HIDE_FROM_ABI constexpr auto end() { return ranges::end(__base_); }8687private:88_LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();89_LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Pred> __pred_;9091static constexpr bool _UseCache = forward_range<_View>;92using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>;93_LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache();94};9596template <class _View, class _Pred>97inline constexpr bool enable_borrowed_range<drop_while_view<_View, _Pred>> = enable_borrowed_range<_View>;9899template <class _Range, class _Pred>100drop_while_view(_Range&&, _Pred) -> drop_while_view<views::all_t<_Range>, _Pred>;101102namespace views {103namespace __drop_while {104105struct __fn {106template <class _Range, class _Pred>107[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, _Pred&& __pred) const108noexcept(noexcept(/**/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))109-> decltype(/*--*/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))) {110return /*-------------*/ drop_while_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred));111}112113template <class _Pred>114requires constructible_from<decay_t<_Pred>, _Pred>115[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const116noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {117return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));118}119};120121} // namespace __drop_while122123inline namespace __cpo {124inline constexpr auto drop_while = __drop_while::__fn{};125} // namespace __cpo126} // namespace views127} // namespace ranges128129#endif // _LIBCPP_STD_VER >= 20130131_LIBCPP_END_NAMESPACE_STD132133_LIBCPP_POP_MACROS134135#endif // _LIBCPP___RANGES_DROP_WHILE_VIEW_H136137138