17#ifndef LIEF_ITERATORS_H
18#define LIEF_ITERATORS_H
33using decay_t =
typename std::decay<T>::type;
46template<class T, typename U = typename decay_t<T>::value_type,
53 using pointer =
typename std::remove_pointer<U>::type*;
54 using reference =
typename std::remove_pointer<U>::type&;
63 container_{std::forward<T>(container)}
65 it_ = std::begin(container_);
69 container_{copy.container_},
70 it_{std::
begin(container_)},
71 distance_{copy.distance_}
73 std::advance(it_, distance_);
85 std::swap(it_, other.it_);
86 std::swap(distance_, other.distance_);
103 if (it_ != std::begin(container_)) {
104 it_ = std::prev(it_);
118 std::advance(it_, movement);
119 distance_ += movement;
125 return (*
this) += -movement;
136 assert(n <
size() &&
"integrity error: out of bound");
141 no_const_this->it_ = std::begin(no_const_this->container_);
142 std::advance(no_const_this->it_, n);
146 no_const_this->it_ = std::begin(no_const_this->container_);
147 std::advance(no_const_this->it_, saved_dist);
165 return distance_ - rhs.distance_;
169 return (rhs - *
this) > 0;
179 return !(*
this < rhs);
184 return !(*
this > rhs);
197 it.it_ = std::end(it.container_);
198 it.distance_ = it.
size();
207 return (
size() == other.
size() && distance_ == other.distance_);
211 return !(*
this == other);
215 return container_.size();
219 return container_.empty();
227 template<
typename V = DT_VAL>
230 assert(*it_ &&
"integrity error: nullptr");
234 template<
typename V = DT_VAL>
241 typename std::enable_if<!std::is_const<pointer_t>::value,
pointer_t>::type
258template<class T, typename U = typename decay_t<T>::value_type,
class CT =
typename std::add_const<T>::type>
263template<class T, typename U = typename decay_t<T>::value_type,
271 using pointer =
typename std::remove_pointer<U>::type*;
272 using reference =
typename std::remove_pointer<U>::type&;
279 using filter_t = std::function<bool (
const typename DT::value_type&)>;
282 container_{std::forward<T>(container)},
286 it_ = std::begin(container_);
288 filters_.push_back(filter),
289 it_ = std::begin(container_);
291 if (it_ != std::end(container_)) {
292 if (!std::all_of(std::begin(filters_), std::end(filters_), [
this] (
const filter_t& f) {
return f(*it_);})) {
299 container_{std::forward<T>(container)},
303 it_ = std::begin(container_);
305 if (it_ != std::end(container_)) {
306 if (!std::all_of(std::begin(filters_), std::end(filters_), [
this] (
const filter_t& f) {
return f(*it_);})) {
313 container_{std::forward<T>(container)},
316 it_ = std::begin(container_);
320 container_{copy.container_},
321 it_{std::
begin(container_)},
322 filters_{copy.filters_},
323 distance_{copy.distance_}
325 std::advance(it_, distance_);
335 std::swap(it_, other.it_);
336 std::swap(filters_, other.filters_);
337 std::swap(size_c_, other.size_c_);
338 std::swap(distance_, other.distance_);
343 filters_.push_back(func);
360 return {container_, filters_};
371 it_end.it_ = it_end.container_.end();
372 it_end.distance_ = it_end.container_.size();
386 template<
typename V = DT_VAL>
389 assert(*it_ &&
"integrity error: nullptr");
393 template<
typename V = DT_VAL>
406 assert(n <
size() &&
"integrity error: out of bound");
414 typename std::enable_if<!std::is_const<pointer_t>::value,
pointer_t>::type
424 if (filters_.empty()) {
425 return container_.size();
434 auto end_iter = std::end(it);
435 for (; it != end_iter; ++it) ++
size;
447 return (container_.size() == other.container_.size() && distance_ == other.distance_);
451 return !(*
this == other);
456 if (it_ == std::end(container_)) {
457 distance_ = container_.size();
462 it_ = std::next(it_);
464 }
while(it_ != std::end(container_) &&
465 !std::all_of(std::begin(filters_), std::end(filters_),
466 [
this] (
const filter_t& f) {
return f(*it_); }));
471 mutable size_t size_c_ = 0;
474 std::vector<filter_t> filters_;
479template<class T, typename U = typename decay_t<T>::value_type,
480 class CT =
typename std::add_const<T>::type>
484template <
typename IteratorT>
489 : begin_(std::move(it_begin)),
490 end_(std::move(it_end)) {}
492 IteratorT
begin()
const {
return begin_; }
493 IteratorT
end()
const {
return end_; }
494 bool empty()
const {
return begin_ == end_; }
Iterator which return a ref on container's values given predicates.
Definition iterators.hpp:265
std::enable_if<!std::is_pointer< V >::value, add_const_t< ref_t > >::type operator*() const
Definition iterators.hpp:395
bool operator==(const filter_iterator &other) const
Definition iterators.hpp:446
filter_iterator(const filter_iterator ©)
Definition iterators.hpp:319
add_const_t< ref_t > operator[](size_t n) const
Definition iterators.hpp:405
filter_iterator cend() const
Definition iterators.hpp:377
typename std::remove_pointer< U >::type * pointer
Definition iterators.hpp:271
filter_iterator(T container, filter_t filter)
Definition iterators.hpp:281
std::forward_iterator_tag iterator_category
Definition iterators.hpp:268
filter_iterator(T container)
Definition iterators.hpp:312
void swap(filter_iterator &other) noexcept
Definition iterators.hpp:333
filter_iterator & operator++()
Definition iterators.hpp:348
std::enable_if<!std::is_const< pointer_t >::value, pointer_t >::type operator->()
Definition iterators.hpp:415
filter_iterator(T container, const std::vector< filter_t > &filters)
Definition iterators.hpp:298
filter_iterator end() const
Definition iterators.hpp:367
typename filter_iterator::pointer pointer_t
Definition iterators.hpp:278
filter_iterator & operator=(filter_iterator other)
Definition iterators.hpp:328
decay_t< U > value_type
Definition iterators.hpp:269
typename filter_iterator::reference ref_t
Definition iterators.hpp:277
std::enable_if<!std::is_const< ref_t >::value, remove_const_t< ref_t > >::type operator*()
Definition iterators.hpp:382
filter_iterator begin() const
Definition iterators.hpp:359
bool empty() const
Definition iterators.hpp:441
U DT_VAL
Definition iterators.hpp:275
ptrdiff_t difference_type
Definition iterators.hpp:270
add_const_t< pointer_t > operator->() const
Definition iterators.hpp:419
std::function< bool(const typename DT::value_type &)> filter_t
Definition iterators.hpp:279
size_t size() const
Definition iterators.hpp:423
std::enable_if< std::is_pointer< V >::value, add_const_t< ref_t > >::type operator*() const
Definition iterators.hpp:388
bool operator!=(const filter_iterator &other) const
Definition iterators.hpp:450
T container_type
Definition iterators.hpp:274
filter_iterator operator++(int)
Definition iterators.hpp:353
decay_t< T > DT
Definition iterators.hpp:276
filter_iterator cbegin() const
Definition iterators.hpp:363
filter_iterator & def(filter_t func)
Definition iterators.hpp:342
typename std::remove_pointer< U >::type & reference
Definition iterators.hpp:272
std::enable_if<!std::is_const< ref_t >::value, remove_const_t< ref_t > >::type operator[](size_t n)
Definition iterators.hpp:401
Definition iterators.hpp:485
IteratorT begin() const
Definition iterators.hpp:492
IteratorT end() const
Definition iterators.hpp:493
bool empty() const
Definition iterators.hpp:494
iterator_range(IteratorT it_begin, IteratorT it_end)
Definition iterators.hpp:488
IteratorT IteratorTy
Definition iterators.hpp:487
Iterator which returns reference on container's values.
Definition iterators.hpp:48
bool operator<=(const ref_iterator &rhs) const
Definition iterators.hpp:183
ref_iterator & operator--()
Definition iterators.hpp:102
size_t size() const
Definition iterators.hpp:214
ref_iterator & operator++()
Definition iterators.hpp:90
void swap(ref_iterator &other) noexcept
Definition iterators.hpp:82
bool operator<(const ref_iterator &rhs) const
Definition iterators.hpp:168
ref_iterator operator-(typename ref_iterator::difference_type n) const
Definition iterators.hpp:158
ref_iterator operator++(int)
Definition iterators.hpp:96
ref_iterator begin() const
Definition iterators.hpp:187
T container_type
Definition iterators.hpp:56
typename ref_iterator::reference ref_t
Definition iterators.hpp:59
ref_iterator operator--(int)
Definition iterators.hpp:110
ref_iterator cend() const
Definition iterators.hpp:202
ref_iterator & operator+=(const typename ref_iterator::difference_type &movement)
Definition iterators.hpp:117
std::bidirectional_iterator_tag iterator_category
Definition iterators.hpp:50
ptrdiff_t difference_type
Definition iterators.hpp:52
ref_iterator operator+(typename ref_iterator::difference_type n) const
Definition iterators.hpp:152
typename std::remove_pointer< U >::type & reference
Definition iterators.hpp:54
ref_iterator cbegin() const
Definition iterators.hpp:191
bool empty() const
Definition iterators.hpp:218
ref_iterator & operator=(ref_iterator other)
Definition iterators.hpp:77
typename std::remove_pointer< U >::type * pointer
Definition iterators.hpp:53
bool operator!=(const ref_iterator &other) const
Definition iterators.hpp:210
std::enable_if<!std::is_const< ref_t >::value, remove_const_t< ref_t > >::type operator[](size_t n)
Definition iterators.hpp:130
bool operator>(const ref_iterator &rhs) const
Definition iterators.hpp:173
bool operator>=(const ref_iterator &rhs) const
Definition iterators.hpp:178
ref_iterator(const ref_iterator ©)
Definition iterators.hpp:68
ref_iterator end() const
Definition iterators.hpp:195
std::enable_if< std::is_pointer< V >::value, add_const_t< ref_t > >::type operator*() const
Definition iterators.hpp:229
std::enable_if<!std::is_pointer< V >::value, add_const_t< ref_t > >::type operator*() const
Definition iterators.hpp:236
ref_iterator & operator-=(const typename ref_iterator::difference_type &movement)
Definition iterators.hpp:124
add_const_t< ref_t > operator[](size_t n) const
Definition iterators.hpp:135
decay_t< U > value_type
Definition iterators.hpp:51
std::enable_if<!std::is_const< ref_t >::value, remove_const_t< ref_t > >::type operator*()
Definition iterators.hpp:223
ref_iterator::difference_type operator-(const ref_iterator &rhs) const
Definition iterators.hpp:164
U DT_VAL
Definition iterators.hpp:57
typename ref_iterator::pointer pointer_t
Definition iterators.hpp:60
ref_iterator(T container)
Definition iterators.hpp:62
std::enable_if<!std::is_const< pointer_t >::value, pointer_t >::type operator->()
Definition iterators.hpp:242
add_const_t< pointer_t > operator->() const
Definition iterators.hpp:246
bool operator==(const ref_iterator &other) const
Definition iterators.hpp:206
decay_t< T > DT
Definition iterators.hpp:58
LIEF namespace.
Definition Abstract/Binary.hpp:32
typename std::add_lvalue_reference< T >::type add_lvalue_reference_t
Definition iterators.hpp:42
typename std::remove_const< T >::type remove_const_t
Definition iterators.hpp:39
iterator_range< T > make_range(T x, T y)
Definition iterators.hpp:500
typename std::decay< T >::type decay_t
Definition iterators.hpp:33
typename std::add_const< T >::type add_const_t
Definition iterators.hpp:36