Slice (= view) for STL containers. More...
#include <slice.hpp>
Public Types | |
typedef container::iterator | iterator |
typedef container::const_iterator | const_iterator |
typedef Internal::remove_cv< typename container::value_type >::type | value_type |
Public Types inherited from Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container > | |
typedef ConstSliceBase< Internal::ContainerStorage, container >::iterator | iterator |
typedef ConstSliceBase< Internal::ContainerStorage, container >::const_iterator | const_iterator |
typedef ConstSliceBase< Internal::ContainerStorage, container >::value_type | value_type |
Public Types inherited from Exiv2::Internal::ConstSliceBase< Internal::ContainerStorage, container > | |
typedef Internal::ContainerStorage< container >::iterator | iterator |
typedef Internal::ContainerStorage< container >::const_iterator | const_iterator |
typedef Internal::ContainerStorage< container >::value_type | value_type |
Public Member Functions | |
Slice (container &cont, size_t begin, size_t end) | |
Construct a slice of the container cont starting at begin (including) and ending before end . More... | |
Slice | subSlice (size_t begin, size_t end) |
Slice< const container > | subSlice (size_t begin, size_t end) const |
Public Member Functions inherited from Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container > | |
MutableSliceBase (container &data, size_t begin, size_t end) | |
value_type & | at (size_t index) |
const value_type & | at (size_t index) const |
iterator | begin () throw () |
iterator | end () throw () |
Public Member Functions inherited from Exiv2::Internal::ConstSliceBase< Internal::ContainerStorage, container > | |
ConstSliceBase (container &data, size_t begin, size_t end) | |
const value_type & | at (size_t index) const |
const_iterator | cbegin () const throw () |
const_iterator | cend () const throw () |
slice_type | subSlice (size_t begin, size_t end) const |
Public Member Functions inherited from Exiv2::Internal::SliceBase | |
SliceBase (size_t begin, size_t end) | |
size_t | size () const throw () |
Additional Inherited Members | |
Protected Types inherited from Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container > | |
typedef ConstSliceBase< Internal::ContainerStorage, container > | base_type |
Protected Member Functions inherited from Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container > | |
ConstSliceBase< Internal::ContainerStorage, const container > | to_const_base () const throw () |
slice_type | subSlice (size_t begin, size_t end) |
Protected Member Functions inherited from Exiv2::Internal::SliceBase | |
void | rangeCheck (size_t index) const |
Protected Attributes inherited from Exiv2::Internal::ConstSliceBase< Internal::ContainerStorage, container > | |
Internal::ContainerStorage< container > | storage_ |
Protected Attributes inherited from Exiv2::Internal::SliceBase | |
const size_t | begin_ |
const size_t | end_ |
Slice (= view) for STL containers.
This is a very simple implementation of slices (i.e. views of sub-arrays) for STL containers that support O(1) element access and random access iterators (like std::vector, std::array and std::string).
A slice represents the semi-open interval [begin, end) and provides a (mutable) view, it does however not own the data! It can be used to conveniently pass parts of containers into functions without having to use iterators or offsets.
In contrast to C++20's std::span<T> it is impossible to read beyond the container's bounds and unchecked access is not-possible (by design).
Example usage:
Slices also offer access via iterators of the same type as the underlying container, so that they can be used in a comparable fashion:
container | A STL container type, like vector or array. Must support array-like access via the at() method. |
|
inline |
Construct a slice of the container cont
starting at begin
(including) and ending before end
.
[in] | cont | Reference to the container |
[in] | begin | First element of the slice. |
[in] | end | First element beyond the slice. |
std::out_of_range | For invalid slice bounds: when end is not larger than begin or when the slice's bounds are larger than the container's size. |
Please note that due to the requirement that end
must be larger than begin
(they cannot be equal) it is impossible to construct a slice with zero length.
|
inline |
Construct a sub-slice of this slice with the given bounds. The bounds are evaluated with respect to the current slice.
[in] | begin | First element in the new slice. |
[in] | end | First element beyond the new slice. |
std::out_of_range | when begin or end are invalid |
References Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::begin(), and Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::end().
|
inline |
Constructs a new constant subSlice. Behaves otherwise exactly like the non-const version.
References Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::begin(), Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::end(), and Exiv2::Internal::MutableSliceBase< Internal::ContainerStorage, container >::to_const_base().