Go to the documentation of this file.
14 #ifndef CPROVER_UTIL_RANGE_H
15 #define CPROVER_UTIL_RANGE_H
18 #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 typename std::result_of<functiont(
value_type)>::type>>
425 using outputt =
typename std::result_of<functiont(
value_type)>::type;
426 auto shared_f = std::make_shared<
427 std::function<outputt(
const typename iteratort::value_type &)>>(
428 std::forward<functiont>(f));
433 std::move(map_begin), std::move(map_end));
436 template <
typename other_iteratort>
445 concat_begin, concat_end);
451 template <
bool same_size = true,
typename other_iteratort>
463 template <
bool same_size = true,
typename containert>
464 auto zip(containert &container)
467 return zip<same_size>(
468 ranget<decltype(container.begin())>{container.begin(), container.end()});
499 const iteratort &
end()
const
506 template <
typename containert>
512 template <
typename containert>
513 operator containert()
const
515 return collect<containert>();
523 template <
typename iteratort>
529 template <
typename containert>
532 return ranget<decltype(container.begin())>(
533 container.begin(), container.end());
539 template <
typename multimapt>
541 equal_range(
const multimapt &multimap,
const typename multimapt::key_type &key)
543 auto iterator_pair = multimap.equal_range(key);
544 return make_range(iterator_pair.first, iterator_pair.second);
547 #endif // CPROVER_UTIL_RANGE_H
typename first_iteratort::value_type value_type
zip_iteratort & operator++()
Preincrement operator.
const iteratort underlying_end
bool operator==(const map_iteratort &other) const
second_iteratort second_end
reference operator*() const
first_iteratort first_begin
concat_iteratort & operator++()
Preincrement operator.
void point_to_first_to_peek()
Ensure that the underlying iterator is always positioned on an element for which f is true.
map_iteratort & operator++()
Preincrement operator.
pointer operator->() const
ranget< zip_iteratort< iteratort, other_iteratort, same_size > > zip(ranget< other_iteratort > other)
Combine two ranges to make a range over pairs.
typename iteratort::value_type value_type
first_iteratort first_end
const iteratort & end() const
reference operator*() const
bool operator==(const concat_iteratort &other) const
std::forward_iterator_tag iterator_category
Iterator which applies some given function f after each increment and returns its result on dereferen...
On increment, increments a first iterator and when the corresponding end iterator is reached,...
std::forward_iterator_tag iterator_category
typename iteratort::reference reference
typename first_iteratort::difference_type difference_type
ranget< iteratort > drop(std::size_t count) &&
Return an new range containing the same elements except for the first count elements.
filter_iteratort operator++(int)
Postincrement operator.
const value_type * operator->() const
typename iteratort::difference_type difference_type
map_iteratort operator++(int)
Postincrement operator.
#define PRECONDITION(CONDITION)
zip_iteratort operator++(int)
Postincrement operator.
A range is a pair of a begin and an end iterators.
typename first_iteratort::reference reference
second_iteratort second_begin
filter_iteratort(std::shared_ptr< std::function< bool(const value_type &)>> f, iteratort underlying, iteratort end)
Filter between underlying and end using f.
std::shared_ptr< outputt > current
Stores the result of f at the current position of the iterator.
auto map(functiont &&f) -> ranget< map_iteratort< iteratort, typename std::result_of< functiont(value_type)>::type >>
The type of elements contained in the resulting range is deduced from the return type of f.
auto zip(containert &container) -> ranget< zip_iteratort< iteratort, decltype(container.begin()), same_size >>
typename iteratort::difference_type difference_type
Iterator which only stops at elements for which some given function f is true.
bool operator!=(const map_iteratort &other) const
zip_iteratort(first_iteratort _first_begin, first_iteratort _first_end, second_iteratort _second_begin, second_iteratort _second_end)
bool operator==(const zip_iteratort &other) const
second_iteratort second_begin
typename iteratort::value_type value_type
ranget(iteratort begin, iteratort end)
concat_iteratort operator++(int)
Postincrement operator.
map_iteratort(iteratort underlying, iteratort underlying_end, std::shared_ptr< std::function< value_type(const typename iteratort::value_type &)>> f)
bool operator!=(const concat_iteratort &other) const
const outputt & reference
std::forward_iterator_tag iterator_category
first_iteratort first_begin
const value_type & operator*() const
concat_iteratort(first_iteratort first_begin, first_iteratort first_end, second_iteratort second_begin)
ranget< iteratort > drop(std::size_t count) const &
Return an new range containing the same elements except for the first count elements.
ranget< filter_iteratort< iteratort > > filter(std::function< bool(const value_type &)> f)
typename iteratort::pointer pointer
pointer operator->() const
std::pair< typename first_iteratort::value_type, typename second_iteratort::value_type > value_type
bool operator==(const filter_iteratort &other) const
std::shared_ptr< std::function< value_type(const typename iteratort::value_type &)> > f
bool operator!=(const zip_iteratort &other) const
std::forward_iterator_tag iterator_category
filter_iteratort & operator++()
Preincrement operator.
value_type * operator->()
containert collect() const
Constructs a collection containing the values, which this range iterates over.
typename first_iteratort::difference_type difference_type
first_iteratort first_end
std::shared_ptr< value_type > current
typename first_iteratort::pointer pointer
bool operator!=(const filter_iteratort &other) const
reference operator*() const
ranget< iteratort > make_range(iteratort begin, iteratort end)
std::shared_ptr< std::function< bool(const value_type &)> > f
Zip two ranges to make a range of pairs.
pointer operator->() const
ranget< concat_iteratort< iteratort, other_iteratort > > concat(ranget< other_iteratort > other)
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.