14 #ifndef CPROVER_UTIL_RANGE_H
15 #define CPROVER_UTIL_RANGE_H
21 #include <type_traits>
25 template <
typename iteratort,
typename outputt>
87 std::function<
value_type(
const typename iteratort::value_type &)>>
f)
92 if(this->underlying != this->underlying_end)
93 current = std::make_shared<outputt>((*this->
f)(*this->underlying));
100 std::function<
value_type(
const typename iteratort::value_type &)>>
110 template <
typename iteratort>
153 return &(*underlying);
164 std::shared_ptr<std::function<
bool(
const value_type &)>>
f,
195 template <
typename first_iteratort,
typename second_iteratort>
201 using pointer =
typename first_iteratort::pointer;
206 std::is_same<value_type, typename first_iteratort::value_type>::value,
207 "Concatenated iterators should have the same value type");
217 return !(*
this == other);
248 return &(*second_begin);
249 return &(*first_begin);
275 typename first_iteratort,
276 typename second_iteratort,
277 bool same_size =
true>
283 typename first_iteratort::value_type,
284 typename second_iteratort::value_type>;
300 return !(*
this == other);
312 "Zipped ranges should have the same size");
339 first_iteratort _first_begin,
340 first_iteratort _first_end,
341 second_iteratort _second_begin,
342 second_iteratort _second_end)
360 std::shared_ptr<value_type>
current =
nullptr;
368 "Zip ranges should have same size");
394 template <
typename iteratort>
408 auto shared_f = std::make_shared<decltype(f)>(std::move(f));
420 template <
typename functiont>
423 using outputt =
typename std::invoke_result<functiont, value_type>::type;
424 auto shared_f = std::make_shared<
425 std::function<outputt(
const typename iteratort::value_type &)>>(
426 std::forward<functiont>(f));
431 std::move(map_begin), std::move(map_end));
434 template <
typename other_iteratort>
443 concat_begin, concat_end);
449 template <
bool same_size = true,
typename other_iteratort>
461 template <
bool same_size = true,
typename containert>
462 auto zip(containert &container)
465 return zip<same_size>(
466 ranget<decltype(container.begin())>{container.begin(), container.end()});
497 const iteratort &
end()
const
504 template <
typename containert>
510 template <
typename containert>
511 operator containert()
const
513 return collect<containert>();
521 template <
typename iteratort>
527 template <
typename containert>
530 return ranget<decltype(container.begin())>(
531 container.begin(), container.end());
537 template <
typename multimapt>
539 equal_range(
const multimapt &multimap,
const typename multimapt::key_type &key)
541 auto iterator_pair = multimap.equal_range(key);
542 return make_range(iterator_pair.first, iterator_pair.second);
Iterator which only stops at elements for which some given function f is true.
void point_to_first_to_peek()
Ensure that the underlying iterator is always positioned on an element for which f is true.
reference operator*() const
typename iteratort::difference_type difference_type
typename iteratort::value_type value_type
typename iteratort::reference reference
filter_iteratort & operator++()
Preincrement operator.
typename iteratort::pointer pointer
std::shared_ptr< std::function< bool(const value_type &)> > f
bool operator==(const filter_iteratort &other) const
bool operator!=(const filter_iteratort &other) const
pointer operator->() const
filter_iteratort(std::shared_ptr< std::function< bool(const value_type &)>> f, iteratort underlying, iteratort end)
Filter between underlying and end using f.
filter_iteratort operator++(int)
Postincrement operator.
const iteratort underlying_end
std::forward_iterator_tag iterator_category
Iterator which applies some given function f after each increment and returns its result on dereferen...
map_iteratort(iteratort underlying, iteratort underlying_end, std::shared_ptr< std::function< value_type(const typename iteratort::value_type &)>> f)
std::shared_ptr< outputt > current
Stores the result of f at the current position of the iterator.
const value_type & operator*() const
typename iteratort::difference_type difference_type
map_iteratort & operator++()
Preincrement operator.
bool operator==(const map_iteratort &other) const
value_type * operator->()
const value_type * operator->() const
std::shared_ptr< std::function< value_type(const typename iteratort::value_type &)> > f
bool operator!=(const map_iteratort &other) const
map_iteratort operator++(int)
Postincrement operator.
std::forward_iterator_tag iterator_category
const outputt & reference
ranget< iteratort > make_range(iteratort begin, iteratort end)
ranget< typename multimapt::const_iterator > equal_range(const multimapt &multimap, const typename multimapt::key_type &key)
Utility function to make equal_range method of multimap easier to use by returning a ranget object.
#define PRECONDITION(CONDITION)
On increment, increments a first iterator and when the corresponding end iterator is reached,...
typename first_iteratort::difference_type difference_type
bool operator!=(const concat_iteratort &other) const
reference operator*() const
concat_iteratort operator++(int)
Postincrement operator.
typename first_iteratort::reference reference
concat_iteratort & operator++()
Preincrement operator.
typename first_iteratort::value_type value_type
typename first_iteratort::pointer pointer
concat_iteratort(first_iteratort first_begin, first_iteratort first_end, second_iteratort second_begin)
first_iteratort first_end
std::forward_iterator_tag iterator_category
pointer operator->() const
first_iteratort first_begin
second_iteratort second_begin
bool operator==(const concat_iteratort &other) const
A range is a pair of a begin and an end iterators.
ranget< concat_iteratort< iteratort, other_iteratort > > concat(ranget< other_iteratort > other)
const iteratort & end() const
ranget(iteratort begin, iteratort end)
ranget< iteratort > drop(std::size_t count) &&
Return an new range containing the same elements except for the first count elements.
ranget< zip_iteratort< iteratort, other_iteratort, same_size > > zip(ranget< other_iteratort > other)
Combine two ranges to make a range over pairs.
auto map(functiont &&f)
The type of elements contained in the resulting range is deduced from the return type of f.
ranget< filter_iteratort< iteratort > > filter(std::function< bool(const value_type &)> f)
ranget< iteratort > drop(std::size_t count) const &
Return an new range containing the same elements except for the first count elements.
typename iteratort::value_type value_type
containert collect() const
Constructs a collection containing the values, which this range iterates over.
auto zip(containert &container) -> ranget< zip_iteratort< iteratort, decltype(container.begin()), same_size >>
Zip two ranges to make a range of pairs.
typename first_iteratort::difference_type difference_type
zip_iteratort(first_iteratort _first_begin, first_iteratort _first_end, second_iteratort _second_begin, second_iteratort _second_end)
second_iteratort second_begin
first_iteratort first_begin
second_iteratort second_end
bool operator!=(const zip_iteratort &other) const
zip_iteratort operator++(int)
Postincrement operator.
reference operator*() const
zip_iteratort & operator++()
Preincrement operator.
first_iteratort first_end
std::shared_ptr< value_type > current
pointer operator->() const
std::forward_iterator_tag iterator_category
std::pair< typename first_iteratort::value_type, typename second_iteratort::value_type > value_type
bool operator==(const zip_iteratort &other) const