a general sequence object with arbitrary size and access functions More...
#include <Sequence.hpp>
Public Types | |
typedef std::function< std::size_t()> | sizer |
type of a functor that returns the size | |
typedef std::function< T(std::size_t)> | getter |
type of a functor that fetches entries | |
typedef std::add_lvalue_reference< typenamestd::remove_pointer< T >::type >::type | Reference_t |
the type used for accessing an entry of this sequence by reference | |
typedef std::add_pointer< typenamestd::remove_reference< T >::type >::type | Pointer_t |
the type used for accessing an entry of this sequence by pointer | |
Public Member Functions | |
Sequence (getter get, sizer size) | |
Constructs a sequence directly from size and access functions. | |
std::size_t | size () const |
size of the sequence | |
T | operator[] (std::size_t index) const |
the index th entry of the sequence | |
operator bool () const | |
true iff size() is nonzero | |
bool | empty () const |
true iff size() is zero | |
Iterator< T > | begin () const |
Iterator pointing to the first entry | |
Iterator< T > | end () const |
Iterator pointing one-past the last entry | |
template<typename U > | |
bool | contains (const U &value) |
true iff the sequence has an entry equal to value | |
template<typename U = Reference_t> | |
Sequence< U > | dereference () const |
If this is a sequence of pointer-like entries, returns a sequence of dereferenced entries. | |
Sequence< Pointer_t > | address () const |
If the entries of this sequence have addresses, returns them as a sequence. | |
template<typename U > | |
Sequence< U > | cast () const |
static_cast s the elements to the specified type | |
Sequence< T > | operator+ (Sequence< T > that) |
concatenates | |
Static Public Member Functions | |
template<typename storage_t = std::remove_reference<T>::type> | |
static Sequence | vector_view (std::vector< storage_t > &vec) |
Given a std::vector , returns its entries as a sequence. | |
a general sequence object with arbitrary size and access functions
User supplies arbitrary std::function
s for size inspection and element access, and this class provides the rest of sequence-like functionality. The result is a general sequence object that may support modification of its entries (if T
is a reference type) but does not support addition or removal of entries. This type of sequence is used in many algorithms in Hexed. A Sequence
object is copyable and moveable, and thus can be passed by value (without copying or moving its entries). This may not be particularly fast. If you need extremely fast entry access, you should use a contiguous array rather than a general sequence. This class is a simpler alternative to the idea of ranges.
Thread safety
Access to entries with [] or iterators is thread-safe. Access to the sequence itself (e.g. with dereference()
, operator+()
, etc.) is not thread safe.
typedef std::add_pointer<typenamestd::remove_reference<T>::type>::type hexed::next::Sequence< T >::Pointer_t |
the type used for accessing an entry of this sequence by pointer
Always a pointer and never a reference, regardless of whether T
is a reference and/or pointer type
typedef std::add_lvalue_reference<typenamestd::remove_pointer<T>::type>::type hexed::next::Sequence< T >::Reference_t |
the type used for accessing an entry of this sequence by reference
Always a reference and never a pointer, regardless of whether T
is a reference and/or pointer type
|
inline |
Constructs a sequence directly from size and access functions.
size
should return the size of the sequence and get(i)
should return the i
th entry. Both size
and get
may be copied, so they should not contain large amounts of data.
|
inline |
true
iff the sequence has an entry equal to value
This is such a common operation it was deemed worthy of a dedicated member function
|
inlinestatic |
Given a std::vector
, returns its entries as a sequence.
This is such a common operation it was deemed worthy of a dedicated member function. You can use this for by-value or by-reference access depending on whether T
is a reference type.