Provides features of a collections, from begin and end iterators. More...
#include <CollectionView.h>
Public Types | |
using | collection_type = range_t |
Type of collection being wrapped. More... | |
using | value_type = typename iter_traits_t::value_type |
using | const_reference = typename iter_traits_t::reference |
using | const_pointer = typename iter_traits_t::pointer |
using | const_iterator = begin_iter_t |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
using | difference_type = typename iter_traits_t::difference_type |
using | size_type = std::size_t |
Public Member Functions | |
Forward access. | |
bool | empty () const noexcept |
Returns whether the collection is empty. More... | |
size_type | size () const noexcept |
Returns the size of the collection. More... | |
const_iterator | cbegin () const noexcept |
Returns an iterator to the begin of the collection. More... | |
end_iter_t | cend () const noexcept |
Returns an iterator past the end of the collection. More... | |
const_iterator | begin () const noexcept |
Returns an iterator to the begin of the collection. More... | |
end_iter_t | end () const noexcept |
Returns an iterator past the end of the collection. More... | |
auto | front () const -> decltype(auto) |
Returns the first element in the collection. More... | |
Backward access. | |
const_reverse_iterator | rbegin () const noexcept |
Returns a reverse iterator to the begin of the collection. More... | |
const_reverse_iterator | rend () const noexcept |
Returns a reverse iterator past the end of the collection. More... | |
const_reverse_iterator | crbegin () const noexcept |
Returns a reverse iterator to the begin of the collection. More... | |
const_reverse_iterator | crend () const noexcept |
Returns a reverse iterator past the end of the collection. More... | |
auto | back () const -> decltype(auto) |
Returns the last element in the collection. More... | |
Random access. | |
auto | operator[] (size_type i) const -> decltype(auto) |
Returns the content of the i -th element. More... | |
auto | at (size_type i) const -> decltype(auto) |
Returns the content of the i -th element. More... | |
Contiguous access. | |
const_pointer | data () const |
Protected Member Functions | |
CollectionView (range_t &&range) | |
Constructor: steals the data from the specified range. More... | |
Private Types | |
using | this_t = CollectionView< Range > |
This type. More... | |
using | range_t = Range |
Type of the range being wrapped. More... | |
using | traits_t = details::RangeTraits< range_t > |
Range traits. More... | |
using | begin_iter_t = typename traits_t::begin_iterator_t |
Type of the begin iterator. More... | |
using | end_iter_t = typename traits_t::end_iterator_t |
Type of the end iterator. More... | |
using | iter_traits_t = std::iterator_traits< begin_iter_t > |
Type of traits of iterator. More... | |
Private Member Functions | |
range_t const & | asRange () const |
Returns this very object, cast back to range_t . More... | |
Friends | |
this_t | details::makeCollectionView (range_t &&) |
Provides features of a collections, from begin and end iterators.
Range | the type of collection to be wrapped |
A collection view is a class that offers a collection-like interface, mostly like the C+ standard library containers, based on two iterators.
The base, wrapped collection is required to respond to begin()
and a end()
global functions. If the desired view is not described by such an object, a temporary one must be created (see makeCollectionView()
).
There are two ways to use this class:
Range
-like containerThe two use cases are both addressed by this class, but helper functions are provided to make it easier to create them as needed.
Range
-like container Here we assume there is somewhere an instance of the object range
which fulfills the requirement of the Range
type above, that is it responds to the requests of a begin()
and a end()
iterator.
To create a collection view of range
, the easiest way is to use wrapCollectionIntoView()
. In the following example the range
object is a STL vector (which does not really need any added interface...):
which will print "1 2 3 4 5 ". Here the wrapped collection object, returned by wrapCollectionIntoView()
, is insubstantial. It can be saved with
or even:
but it will be just a (constant) reference to something else.
In this approach, we have two iterators to an existing collection, and we want to use them as extremes of a "virtual" collection. Again we use a STL vector as a base container for the example. Here we want to see a subrange of it as a new collection. We use makeCollectionView()
.
will print "0 1 2 3 4 5 6 7 8 9 ".
The function lar::makeCollectionView()
creates a view owning the information the view requires. Similarly, a new class can be defined which does the same, by simply deriving it from lar::CollectionView
:
aftter which MyCollection
interface can be enriched as needed. The IntViewBase_t
alias is a way to overcome the fact that the name IntVector
can't be used inside MyCollection
because it's actually a private base class (the base class, even if not direct, will hide IntVector
, even if, being private, it can't even be used). Another way is to fully qualify its name (e.g. ::IntVector
).
Note that to avoid accidental copies, lar::CollectionView
objects can't be directly instantiated: using directly IntViewBase_t
will not be allowed.
Definition at line 98 of file CollectionView.h.
|
private |
Type of the begin iterator.
Definition at line 292 of file CollectionView.h.
using lar::CollectionView< Range >::collection_type = range_t |
Type of collection being wrapped.
Definition at line 300 of file CollectionView.h.
using lar::CollectionView< Range >::const_iterator = begin_iter_t |
Definition at line 308 of file CollectionView.h.
using lar::CollectionView< Range >::const_pointer = typename iter_traits_t::pointer |
Definition at line 306 of file CollectionView.h.
using lar::CollectionView< Range >::const_reference = typename iter_traits_t::reference |
Definition at line 304 of file CollectionView.h.
using lar::CollectionView< Range >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Definition at line 310 of file CollectionView.h.
using lar::CollectionView< Range >::difference_type = typename iter_traits_t::difference_type |
Definition at line 311 of file CollectionView.h.
|
private |
Type of the end iterator.
Definition at line 294 of file CollectionView.h.
|
private |
Type of traits of iterator.
Definition at line 297 of file CollectionView.h.
|
private |
Type of the range being wrapped.
Definition at line 288 of file CollectionView.h.
using lar::CollectionView< Range >::size_type = std::size_t |
Definition at line 312 of file CollectionView.h.
|
private |
This type.
Definition at line 287 of file CollectionView.h.
|
private |
Range traits.
Definition at line 289 of file CollectionView.h.
using lar::CollectionView< Range >::value_type = typename iter_traits_t::value_type |
Definition at line 302 of file CollectionView.h.
|
inlineexplicitprotected |
Constructor: steals the data from the specified range.
Definition at line 408 of file CollectionView.h.
|
inlineprivate |
Returns this very object, cast back to range_t
.
Definition at line 416 of file CollectionView.h.
|
inline |
Returns the content of the i
-th element.
Definition at line 372 of file CollectionView.h.
|
inline |
Returns the last element in the collection.
Definition at line 360 of file CollectionView.h.
|
inlinenoexcept |
Returns an iterator to the begin of the collection.
Definition at line 332 of file CollectionView.h.
|
inlinenoexcept |
Returns an iterator to the begin of the collection.
Definition at line 324 of file CollectionView.h.
|
inlinenoexcept |
Returns an iterator past the end of the collection.
Definition at line 328 of file CollectionView.h.
|
inlinenoexcept |
Returns a reverse iterator to the begin of the collection.
Definition at line 352 of file CollectionView.h.
|
inlinenoexcept |
Returns a reverse iterator past the end of the collection.
Definition at line 356 of file CollectionView.h.
|
inline |
Definition at line 388 of file CollectionView.h.
|
inlinenoexcept |
Returns whether the collection is empty.
Definition at line 318 of file CollectionView.h.
|
inlinenoexcept |
Returns an iterator past the end of the collection.
Definition at line 335 of file CollectionView.h.
|
inline |
Returns the first element in the collection.
Definition at line 338 of file CollectionView.h.
|
inline |
Returns the content of the i
-th element.
Definition at line 368 of file CollectionView.h.
|
inlinenoexcept |
Returns a reverse iterator to the begin of the collection.
Definition at line 346 of file CollectionView.h.
|
inlinenoexcept |
Returns a reverse iterator past the end of the collection.
Definition at line 349 of file CollectionView.h.
|
inlinenoexcept |
Returns the size of the collection.
Definition at line 321 of file CollectionView.h.
|
friend |