C++ Ranges::bidirectional_range, commom_range, contiguous range Introduction














































C++ Ranges::bidirectional_range, commom_range, contiguous range Introduction




In this series of articles on RANGES with C++, today we are going to see libraries of std::ranges::bidirectional_range , std::ranges::Common_Range and std::ranges::Contiguous_range
____________________________________________________________________________________

INTRODUCTION to RANGES LIBRARY HAS BEEN DONE IN MY PREVIOUS ARTICLE.

All the libraries defined below are included in the header <ranger> and <iterator>.


std::ranges::bidirectional range

First understand what is bidirectional iterator::

 It has the ability to move an iterator backwards as well as forward.

Birectional_range is a refinement of Range  for which ranges::begin returns Bidirectional_Iterator.

template<class A>
  concept BidirectionalRange =
    ForwardRange<A> && BidirectionalIterator<iterator_t<A>>;

std::ranges::Common_Range

The CommonRange concept is a refinement of Range for which ranges::begin and ranges::end return the same type (e.g. all standard library containers).

template<class A>
  concept CommonRange = Range<T> && Same<iterator_t<A>, sentinel_t<A>>;

std::ranges::Contiguous_range

First understand what is contiguous iterator::

This iterator concept provides the ability to store the denoted elements contiguously in the memory.

In Contiguous_Range, ranges::begin returns a model of Contiguous_Iterator and the customization point ranges::data is usable.

template<class A>
  concept ContiguousRange =
    RandomAccessRange<A> && ContiguousIterator<iterator_t<A>> &&
    requires(A& t) {
      { ranges::data(t) } -> Same<std::add_pointer_t<iter_reference_t<iterator_t<A>>>>;
    };


Comments