Loading [MathJax]/extensions/tex2jax.js
Iros
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Loading...
Searching...
No Matches
take_while_view.h
Go to the documentation of this file.
1#pragma once
2
8#include "di/meta/util.h"
9#include "di/util/addressof.h"
11
12namespace di::container {
13template<concepts::View View, typename Pred>
14requires(concepts::InputContainer<View> && concepts::Object<Pred> &&
15 concepts::IndirectUnaryPredicate<Pred const, meta::ContainerIterator<View>>)
17private:
18 template<bool is_const>
20
21 template<bool is_const>
23
24 template<bool is_const>
25 class Sentinel {
26 public:
27 Sentinel() = default;
28
29 constexpr explicit Sentinel(Sent<is_const> base, Pred const* predicate)
30 : m_base(base), m_predicate(predicate) {}
31
32 constexpr Sentinel(Sentinel<!is_const> other)
33 requires(is_const && concepts::ConvertibleTo<Sent<false>, Sent<true>>)
34 : m_base(other.base()), m_predicate(other.m_predicate) {}
35
36 constexpr auto base() const -> Sent<is_const> { return m_base; }
37
38 private:
39 constexpr friend auto operator==(Iter<is_const> const& a, Sentinel const& b) -> bool {
40 return a == b.base() || !function::invoke(*b.m_predicate, *a);
41 }
42
43 Sent<is_const> m_base {};
44 Pred const* m_predicate { nullptr };
45 };
46
47public:
50 = default;
51
52 constexpr explicit TakeWhileView(View base, Pred predicate)
53 : m_base(util::move(base)), m_predicate(util::move(predicate)) {}
54
55 constexpr auto base() const& -> View
56 requires(concepts::CopyConstructible<View>)
57 {
58 return m_base;
59 }
60 constexpr auto base() && -> View { return util::move(m_base); }
61
62 constexpr auto pred() const -> Pred const& { return m_predicate.value(); }
63
64 constexpr auto begin()
66 {
67 return container::begin(m_base);
68 }
69
70 constexpr auto begin() const
71 requires(concepts::Container<View const> && concepts::IndirectUnaryPredicate<Pred const, Iter<true>>)
72 {
73 return container::begin(m_base);
74 }
75
76 constexpr auto end()
78 {
79 return Sentinel<false>(container::end(m_base), util::addressof(m_predicate.value()));
80 }
81
82 constexpr auto end() const
83 requires(concepts::Container<View const> && concepts::IndirectUnaryPredicate<Pred const, Iter<true>>)
84 {
85 return Sentinel<true>(container::end(m_base), util::addressof(m_predicate.value()));
86 }
87
88private:
89 View m_base {};
90 util::RebindableBox<Pred> m_predicate;
91};
92
93template<typename Con, typename Pred>
95}
Definition take_while_view.h:16
constexpr auto base() const &-> View requires(concepts::CopyConstructible< View >)
Definition take_while_view.h:55
constexpr TakeWhileView(View base, Pred predicate)
Definition take_while_view.h:52
constexpr auto base() &&-> View
Definition take_while_view.h:60
constexpr auto begin()
Definition take_while_view.h:64
constexpr auto pred() const -> Pred const &
Definition take_while_view.h:62
constexpr auto end()
Definition take_while_view.h:76
constexpr auto end() const
Definition take_while_view.h:82
constexpr auto begin() const
Definition take_while_view.h:70
Definition view_interface.h:26
Definition view.h:35
Definition rebindable_box.h:42
Definition operations.h:99
Definition operations.h:27
Definition simple_view.h:11
Definition any_storable.h:9
Definition sequence.h:12
constexpr auto move
Definition move.h:38
TakeWhileView(Con &&, Pred) -> TakeWhileView< meta::AsView< Con >, Pred >
constexpr auto operator==(MoveIterator< Iter > const &a, MoveIterator< U > const &b) -> bool
Definition move_iterator.h:85
constexpr auto end
Definition end.h:47
constexpr auto begin
Definition begin.h:44
constexpr auto invoke
Definition invoke.h:100
decltype(container::end(util::declval< T & >())) ContainerSentinel
Definition container_sentinel.h:8
decltype(container::begin(util::declval< T & >())) ContainerIterator
Definition container_iterator.h:8
Definition vocab.h:96