cxxomfort  rel.20210622
Simple backports for C++ - http://ryan.gulix.cl/fossil.cgi/cxxomfort/
Public Types | Public Member Functions | List of all members
array_ref< T, IdxType > Class Template Reference

An object representing a reference or slice of a contiguous area of memory of type T . More...

Public Types

typedef T element_type
 Type of the data contained in the view.
 
typedef std::remove_cv< element_type >::type value_type
 Type of variables of the type of the pointed-to data.
 
typedef std::add_const< value_type >::type const_value_type
 const version of the value_type .
 
typedef ptrdiff_t difference_type
 Type for the distance between pointers or iterators.
 
typedef IdxType size_type
 Type for subscript / indexed access (eg.: operator[]).
 
typedef std::add_pointer< element_type >::type pointer
 Type of a pointer to a contained value; potentially writable.
 
typedef std::add_pointer< element_type const >::type const_pointer
 Type of a pointer to a contained value; view-only.
 
typedef pointer iterator
 Iterator type; potentially writable.
 
typedef const_pointer const_iterator
 Iterator type; view-only.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse iterator type; potentially writable.
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Reverse iterator type; view-only.
 

Public Member Functions

constexpr array_ref () noexcept=default
 Trivial constructor; creates a view to nothing.
 
constexpr array_ref (array_ref const &) noexcept=default
 Copy constructor (trivial)
 
constexpr array_refoperator= (array_ref const &) noexcept=default
 Assignment operator (trivial)
 
CXXO_CONSTEXPR array_ref (pointer p, size_type len) CXXO_NOEXCEPTNOTHROW
 Construct a view to a buffer starting at p and of len units long.
 
CXXO_CONSTEXPR array_ref (std::nullptr_t, pointer p, pointer q) CXXO_NOEXCEPTNOTHROW
 Construct a view to a buffer starting at p and ending at q (not in the original n3334 proposal).
 
template<size_t N>
CXXO_CONSTEXPR array_ref (T(&arr)[N]) CXXO_NOEXCEPTNOTHROW
 Constructs a view over a native C array.
 
reference operator[] (size_type i) CXXO_NOEXCEPTNOTHROW
 Unchecked access to the i -th element.
 
CXXO_CONSTEXPR const_reference operator[] (size_type i) const CXXO_NOEXCEPTNOTHROW
 Unchecked access to the i -th element.
 
reference at (size_type i)
 Checked access to the i -th element; throw.
 
const_reference at (size_type i) const
 Checked access to the i -th element; throw.
 
reference at_or (size_type i, reference alt) CXXO_NOEXCEPTNOTHROW
 Checked access to the i -th element; returns an alternative if it doesn't exist.
 
CXXO_CONSTEXPR const_reference at_or (size_type i, const_reference alt) const CXXO_NOEXCEPTNOTHROW
 Checked access to the i -th element; returns an alternative if it doesn't exist.
 
CXXO_CONSTEXPR size_type size () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR bool empty () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR14 pointer data () CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR const_pointer data () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR size_type size_bytes () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR const_iterator cbegin () const CXXO_NOEXCEPTNOTHROW
 begin
 
CXXO_CONSTEXPR const_iterator cend () const CXXO_NOEXCEPTNOTHROW
 end
 
iterator begin () CXXO_NOEXCEPTNOTHROW
 begin
 
iterator end () CXXO_NOEXCEPTNOTHROW
 end
 
CXXO_CONSTEXPR const_iterator begin () const CXXO_NOEXCEPTNOTHROW
 begin
 
CXXO_CONSTEXPR const_iterator end () const CXXO_NOEXCEPTNOTHROW
 end
 
CXXO_CONSTEXPR const_reverse_iterator crbegin () const CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
CXXO_CONSTEXPR const_reverse_iterator crend () const CXXO_NOEXCEPTNOTHROW
 reverse-end
 
reverse_iterator rbegin () CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
reverse_iterator rend () CXXO_NOEXCEPTNOTHROW
 reverse-end
 
const_reverse_iterator rbegin () const CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
const_reverse_iterator rend () const CXXO_NOEXCEPTNOTHROW
 reverse-end
 
const_iterator front () const CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the 0th element.
 
iterator front () CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the 0th element.
 
const_iterator back () const CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the last element.
 
iterator back () CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the last element.
 
CXXO_CONSTEXPR array_ref substr (size_type pos, size_type count) const
 Returns a view to the count -elements subsequence starting from pos .
 
array_ref substr (size_type pos) const
 
array_ref leftmost (size_type n) const CXXO_NOEXCEPTNOTHROW
 Returns a view to the leftmost (first) n elements.
 
array_ref rightmost (size_type n) const CXXO_NOEXCEPTNOTHROW
 Returns a view to the rightmost (last) n elements.
 
array_ref slice (difference_type pos, size_type count) const
 Returns a view of sub-contents from position pos which can be negative, ala PHP, JS.
 
array_ref slice (difference_type pos) const
 
array_ref without_back_n (size_type n) const
 Removes the last n elements.
 
array_ref without_front_n (size_type n) const
 Removes the first n elements.
 
array_ref without_back () const
 Returns a view with the last element removed.
 
array_ref without_front () const
 Returns a view with the first element removed.
 

Detailed Description

template<class T, class IdxType = size_t>
class cxxomfort::impl::array_ref::array_ref< T, IdxType >

An object representing a reference or slice of a contiguous area of memory of type T .

Template Parameters
TType of the kind of value contained in the view.
IdxTypeA numeric type to be used as the index, defaults to size_t .
Supplements:

A array_ref is a non-owning view of a sequence of contiguous elements via a simple {pointer+length} package. In many ways it could be considered an analogue to std::array except it doesn't actually hold the data (hence the name, array_ref ), and to std::reference_wrapper.

Being a reference/view type, it is good to pass by value. Also, iterator types are raw pointers.

This implementation is intended to be used for sequences of const elements (ie.: template argument is T const).

The utility function arrayref() and carrayref() help create array_refs from contexts where they can be needed.

See also: std::array, std::vector, seq_ .

Differences with std::basic_string_view

See Also

array_ref is based in the original publication "n3334" by Jeffrey Yasskin

See also
WG21 index n3334 array_ref container/span @ cppreference

Member Function Documentation

◆ size()

CXXO_CONSTEXPR size_type size ( ) const
inline

◆ empty()

CXXO_CONSTEXPR bool empty ( ) const
inline
Returns
bool .

Referenced by array_ref< Ch const >::rightmost().

◆ data() [1/2]

CXXO_CONSTEXPR14 pointer data ( )
inline

◆ data() [2/2]

CXXO_CONSTEXPR const_pointer data ( ) const
inline
Returns
pointer to the view's data.

◆ size_bytes()

CXXO_CONSTEXPR size_type size_bytes ( ) const
inline
Returns
size of the view in bytes.

◆ substr()

array_ref substr ( size_type  pos) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ slice()

array_ref slice ( difference_type  pos) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


The documentation for this class was generated from the following file: