sbepp
Loading...
Searching...
No Matches
sbepp::detail::static_array_ref< Byte, Value, N, Tag > Class Template Reference

Represents reference to fixed-size array. More...

#include <sbepp.hpp>

Inheritance diagram for sbepp::detail::static_array_ref< Byte, Value, N, Tag >:
sbepp::detail::byte_range< Byte >

Public Types

using element_type = detail::apply_cv_qualifiers_t<Byte, Value>
 final element type. value_type with the same cv-qualifiers as Byte
 
using value_type = Value
 same as Value
 
using size_type = std::size_t
 std::size_t
 
using difference_type = std::ptrdiff_t
 std::ptrdiff_t
 
using reference = element_type&
 element reference type
 
using pointer = element_type*
 element pointer type
 
using iterator = pointer
 iterator type. Satisfies std::random_access_iterator
 
using reverse_iterator = std::reverse_iterator<iterator>
 reverse iterator type
 
using tag = Tag
 type tag
 

Public Member Functions

constexpr reference operator[] (size_type pos) const noexcept
 Access element at pos
 
constexpr reference front () const noexcept
 Access the first element.
 
constexpr reference back () const noexcept
 Access the last element.
 
constexpr pointer data () const noexcept
 Direct access to the underlying array.
 
constexpr iterator begin () const noexcept
 Returns an iterator to the beginning.
 
constexpr iterator end () const noexcept
 Returns an iterator to the end.
 
constexpr reverse_iterator rbegin () const noexcept
 Returns a reverse iterator to the beginning.
 
constexpr reverse_iterator rend () const noexcept
 Returns a reverse iterator to the end.
 
constexpr static_array_ref< Byte, detail::remove_cv_t< Byte >, N, Tag > raw () const noexcept
 Returns static_array_ref<Byte, Byte, N, Tag>.
 
constexpr std::size_t strlen () const noexcept
 Calculates string length from left to right.
 
constexpr std::size_t strlen_r () const noexcept
 Calculates string length from right to left.
 
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator assign_string (const char *str, const eos_null eos_mode=eos_null::all) const noexcept
 Assigns null-terminated string.
 
template<typename R , typename = enable_if_t<!std::is_const<Byte>::value && is_range<R>::value>>
constexpr iterator assign_string (R &&r, const eos_null eos_mode=eos_null::all) const
 Assigns string represented by a range.
 
template<typename R , typename = enable_if_t<!std::is_const<Byte>::value && is_range<R>::value>>
constexpr iterator assign_range (R &&r) const
 Assigns range.
 
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr void fill (const value_type value) const noexcept
 Assigns value to all elements.
 
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator assign (size_type count, const value_type value) const noexcept
 Assigns value to first count elements.
 
template<typename InputIt , typename = enable_if_writable_t<Byte, InputIt>>
constexpr iterator assign (InputIt first, InputIt last) const
 Assigns elements from [first; last) range to first elements.
 
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator assign (std::initializer_list< value_type > ilist) const noexcept
 Assigns initializer list to first elements.
 
- Public Member Functions inherited from sbepp::detail::byte_range< Byte >
 byte_range ()=default
 Initializes to nullptr
 
constexpr byte_range (Byte *begin, Byte *end) noexcept
 Constructs from a pair of pointers.
 
constexpr byte_range (Byte *ptr, const std::size_t size) noexcept
 Constructs from pointer and size.
 
template<typename Byte2 , typename = enable_if_convertible_t<Byte2, Byte>>
constexpr byte_range (const byte_range< Byte2 > &other) noexcept
 Copy constructor. Available if Byte2* is convertible to Byte*
 

Static Public Member Functions

static constexpr bool empty () noexcept
 Checks if size() != 0
 
static constexpr size_type size () noexcept
 Returns N
 
static constexpr size_type max_size () noexcept
 Returns size()
 

Detailed Description

template<typename Byte, typename Value, std::size_t N, typename Tag>
class sbepp::detail::static_array_ref< Byte, Value, N, Tag >

Represents reference to fixed-size array.

The general precondition for most functions is that current buffer should be able to hold all elements

Template Parameters
Bytebyte type
Valuearray element type from schema
Narray length
Tagtype tag

Member Function Documentation

◆ assign() [1/3]

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename InputIt , typename = enable_if_writable_t<Byte, InputIt>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign ( InputIt first,
InputIt last ) const
inlineconstexpr

Assigns elements from [first; last) range to first elements.

Returns
iterator past the last written byte
Precondition
std::distance(first, last) <= size()

◆ assign() [2/3]

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign ( size_type count,
const value_type value ) const
inlineconstexprnoexcept

Assigns value to first count elements.

Parameters
countnumber of elements to assign to
valuevalue to assign
Returns
iterator past the last written byte
Precondition
count <= size()

◆ assign() [3/3]

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign ( std::initializer_list< value_type > ilist) const
inlineconstexprnoexcept

Assigns initializer list to first elements.

Parameters
ilistvalues to assign
Returns
iterator past the last written byte
Precondition
ilist.size() <= size()

◆ assign_range()

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename R , typename = enable_if_t<!std::is_const<Byte>::value && is_range<R>::value>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign_range ( R && r) const
inlineconstexpr

Assigns range.

Parameters
rrange to assign. In C++20, required to satisfy std::ranges::range, or std::begin(r)/std::end(r) as valid expressions for older C++ versions
Returns
iterator past the last written byte
Precondition
range_size(r) <= size()

◆ assign_string() [1/2]

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign_string ( const char * str,
const eos_null eos_mode = eos_null::all ) const
inlineconstexprnoexcept

Assigns null-terminated string.

Parameters
strnull-terminated string
eos_modedetermines how many null bytes to write after the end-of-string when strlen(str) < size()
Returns
iterator past the last written string character (without null bytes)
Precondition
str != nullptr
strlen(str) <= size()

◆ assign_string() [2/2]

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename R , typename = enable_if_t<!std::is_const<Byte>::value && is_range<R>::value>>
constexpr iterator sbepp::detail::static_array_ref< Byte, Value, N, Tag >::assign_string ( R && r,
const eos_null eos_mode = eos_null::all ) const
inlineconstexpr

Assigns string represented by a range.

Parameters
rstring range to assign. In C++20, required to satisfy std::ranges::range, or std::begin(r)/std::end(r) as valid expressions for older C++ versions
eos_modedetermines how many null bytes to write after the end-of-string when range_size(r) < size()
Returns
iterator past the last written string character (without null bytes)
Precondition
range_size(r) <= size()

◆ fill()

template<typename Byte , typename Value , std::size_t N, typename Tag >
template<typename T = void, typename = enable_if_writable_t<Byte, T>>
constexpr void sbepp::detail::static_array_ref< Byte, Value, N, Tag >::fill ( const value_type value) const
inlineconstexprnoexcept

Assigns value to all elements.

Parameters
valuevalue to assign

◆ operator[]()

template<typename Byte , typename Value , std::size_t N, typename Tag >
constexpr reference sbepp::detail::static_array_ref< Byte, Value, N, Tag >::operator[] ( size_type pos) const
inlineconstexprnoexcept

Access element at pos

Precondition
pos < size()

◆ raw()

template<typename Byte , typename Value , std::size_t N, typename Tag >
constexpr static_array_ref< Byte, detail::remove_cv_t< Byte >, N, Tag > sbepp::detail::static_array_ref< Byte, Value, N, Tag >::raw ( ) const
inlineconstexprnoexcept

Returns static_array_ref<Byte, Byte, N, Tag>.

Useful in constexpr context to modify an array which has different Byte and Value types. Example:

a1[0] = 'a'; // error: cannot convert `char` to `std::byte`
a1.raw()[0] = std::byte{'a'}; // OK
Represents reference to fixed-size array.
Definition sbepp.hpp:2989
constexpr static_array_ref< Byte, detail::remove_cv_t< Byte >, N, Tag > raw() const noexcept
Returns static_array_ref<Byte, Byte, N, Tag>.
Definition sbepp.hpp:3106

◆ strlen()

template<typename Byte , typename Value , std::size_t N, typename Tag >
constexpr std::size_t sbepp::detail::static_array_ref< Byte, Value, N, Tag >::strlen ( ) const
inlineconstexprnoexcept

Calculates string length from left to right.

Calculates stored string length by looking for the first null character from left to right. If not found, returns size().

◆ strlen_r()

template<typename Byte , typename Value , std::size_t N, typename Tag >
constexpr std::size_t sbepp::detail::static_array_ref< Byte, Value, N, Tag >::strlen_r ( ) const
inlineconstexprnoexcept

Calculates string length from right to left.

Calculates stored string length by looking for the first non-null character from right to left. If not found, returns 0.


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