Nui
iterator_accessor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <type_traits>
4 #include <memory>
5 namespace Nui
6 {
7  template <typename ContainerT>
9  {
10  public:
11  using IteratorType = typename ContainerT::iterator;
12  using ConstIteratorType = typename ContainerT::const_iterator;
13 
14  explicit IteratorAccessor(ContainerT& container)
15  : container_{&container}
16  {}
17  ~IteratorAccessor() = default;
22 
24  requires(std::is_const_v<ContainerT>)
25  {
26  return container_->begin();
27  }
28 
30  requires(std::is_const_v<ContainerT>)
31  {
32  return container_->end();
33  }
34 
36  requires(!std::is_const_v<ContainerT>)
37  {
38  return container_->begin();
39  }
40 
41  IteratorType end() const
42  requires(!std::is_const_v<ContainerT>)
43  {
44  return container_->end();
45  }
46 
47  private:
48  ContainerT* container_;
49  };
50 
51  template <typename ContainerT>
52  class IteratorAccessor<std::weak_ptr<ContainerT>>
53  {
54  public:
55  using IteratorType = typename ContainerT::iterator;
56  using ConstIteratorType = typename ContainerT::const_iterator;
57 
58  explicit IteratorAccessor(std::weak_ptr<ContainerT> container)
59  : container_{std::move(container)}
60  {}
61  ~IteratorAccessor() = default;
66 
68  requires(std::is_const_v<ContainerT>)
69  {
70  return container_.lock()->begin();
71  }
72 
74  requires(std::is_const_v<ContainerT>)
75  {
76  return container_.lock()->end();
77  }
78 
80  requires(!std::is_const_v<ContainerT>)
81  {
82  return container_.lock()->begin();
83  }
84 
85  IteratorType end() const
86  requires(!std::is_const_v<ContainerT>)
87  {
88  return container_.lock()->end();
89  }
90 
91  private:
92  std::weak_ptr<ContainerT> container_;
93  };
94 
95  template <typename ContainerT>
96  class IteratorAccessor<std::shared_ptr<ContainerT>>
97  {
98  public:
99  using IteratorType = typename ContainerT::iterator;
100  using ConstIteratorType = typename ContainerT::const_iterator;
101 
102  explicit IteratorAccessor(std::weak_ptr<ContainerT> container)
103  : container_{std::move(container)}
104  {}
105  ~IteratorAccessor() = default;
110 
112  requires(std::is_const_v<ContainerT>)
113  {
114  return container_->begin();
115  }
116 
118  requires(std::is_const_v<ContainerT>)
119  {
120  return container_->end();
121  }
122 
124  requires(!std::is_const_v<ContainerT>)
125  {
126  return container_->begin();
127  }
128 
130  requires(!std::is_const_v<ContainerT>)
131  {
132  return container_->end();
133  }
134 
135  private:
136  std::shared_ptr<ContainerT> container_;
137  };
138 
139  // Deduction guide for const ContainerT
140  template <typename ContainerT>
142 
143  // Deduction guide for non-const ContainerT
144  template <typename ContainerT>
146 }
IteratorType begin() const requires(!std
Definition: iterator_accessor.hpp:123
ConstIteratorType begin() const requires(std
Definition: iterator_accessor.hpp:111
IteratorAccessor & operator=(IteratorAccessor const &)=default
ConstIteratorType end() const requires(std
Definition: iterator_accessor.hpp:117
IteratorAccessor(std::weak_ptr< ContainerT > container)
Definition: iterator_accessor.hpp:102
typename ContainerT::iterator IteratorType
Definition: iterator_accessor.hpp:99
IteratorAccessor & operator=(IteratorAccessor &&)=default
IteratorAccessor(IteratorAccessor const &)=default
IteratorType end() const requires(!std
Definition: iterator_accessor.hpp:129
typename ContainerT::const_iterator ConstIteratorType
Definition: iterator_accessor.hpp:100
IteratorAccessor(IteratorAccessor const &)=default
IteratorType end() const requires(!std
Definition: iterator_accessor.hpp:85
typename ContainerT::const_iterator ConstIteratorType
Definition: iterator_accessor.hpp:56
IteratorType begin() const requires(!std
Definition: iterator_accessor.hpp:79
ConstIteratorType end() const requires(std
Definition: iterator_accessor.hpp:73
IteratorAccessor(std::weak_ptr< ContainerT > container)
Definition: iterator_accessor.hpp:58
IteratorAccessor & operator=(IteratorAccessor &&)=default
typename ContainerT::iterator IteratorType
Definition: iterator_accessor.hpp:55
IteratorAccessor & operator=(IteratorAccessor const &)=default
ConstIteratorType begin() const requires(std
Definition: iterator_accessor.hpp:67
Definition: iterator_accessor.hpp:9
ConstIteratorType begin() const requires(std
Definition: iterator_accessor.hpp:23
IteratorAccessor(ContainerT &container)
Definition: iterator_accessor.hpp:14
typename ContainerT::iterator IteratorType
Definition: iterator_accessor.hpp:11
ConstIteratorType end() const requires(std
Definition: iterator_accessor.hpp:29
typename ContainerT::const_iterator ConstIteratorType
Definition: iterator_accessor.hpp:12
IteratorType begin() const requires(!std
Definition: iterator_accessor.hpp:35
~IteratorAccessor()=default
IteratorAccessor(IteratorAccessor const &)=default
IteratorAccessor & operator=(IteratorAccessor const &)=default
IteratorAccessor & operator=(IteratorAccessor &&)=default
IteratorType end() const requires(!std
Definition: iterator_accessor.hpp:41
IteratorAccessor(IteratorAccessor &&)=default
Definition: file_dialog.hpp:6
IteratorAccessor(ContainerT const &) -> IteratorAccessor< const ContainerT >
requires(IsObservedLike< ObservedValues > &&...) ObservedValueCombinator< std
Definition: observed_value_combinator.hpp:191