userver: utils::FixedArray< T > Class Template Reference
Loading...
Searching...
No Matches
utils::FixedArray< T > Class Template Referencefinal

#include <userver/utils/fixed_array.hpp>

Detailed Description

template<class T>
class utils::FixedArray< T >

A fixed-size array with the size determined at runtime.

The array also allows initializing each of the array elements with the same parameters:

class NonDefaultConstructible final {
public:
explicit NonDefaultConstructible(std::string str) : str_(std::move(str)) {}
std::string GetString() const { return str_; }
private:
std::string str_;
};
ASSERT_EQ(array.size(), 42);
ASSERT_EQ(array[0].GetString(), "The string");
ASSERT_EQ(array[14].GetString(), "The string");
ASSERT_EQ(array[41].GetString(), "The string");

Definition at line 33 of file fixed_array.hpp.

Public Types

using iterator = T*
 
using const_iterator = const T*
 

Public Member Functions

 FixedArray ()=default
 Make an empty array.
 
template<class... Args>
 FixedArray (std::size_t size, Args &&... args)
 Make an array and initialize each element with "args".
 
 FixedArray (FixedArray &&other) noexcept
 
FixedArrayoperator= (FixedArray &&other) noexcept
 
 FixedArray (const FixedArray &)=delete
 
FixedArrayoperator= (const FixedArray &)=delete
 
std::size_t size () const noexcept
 
bool empty () const noexcept
 
const T & operator[] (std::size_t i) const noexcept
 
T & operator[] (std::size_t i) noexcept
 
T & front () noexcept
 
const T & front () const noexcept
 
T & back () noexcept
 
const T & back () const noexcept
 
T * data () noexcept
 
const T * data () const noexcept
 
T * begin () noexcept
 
T * end () noexcept
 
const T * begin () const noexcept
 
const T * end () const noexcept
 
const T * cbegin () const noexcept
 
const T * cend () const noexcept
 
template<class GeneratorFunc >
 FixedArray (impl::GenerateTag, std::size_t size, GeneratorFunc &&generator)
 

Member Typedef Documentation

◆ const_iterator

template<class T >
using utils::FixedArray< T >::const_iterator = const T*

Definition at line 36 of file fixed_array.hpp.

◆ iterator

template<class T >
using utils::FixedArray< T >::iterator = T*

Definition at line 35 of file fixed_array.hpp.

Constructor & Destructor Documentation

◆ FixedArray() [1/3]

template<class T >
template<class... Args>
utils::FixedArray< T >::FixedArray ( std::size_t size,
Args &&... args )
explicit

Make an array and initialize each element with "args".

Definition at line 115 of file fixed_array.hpp.

◆ FixedArray() [2/3]

template<class T >
utils::FixedArray< T >::FixedArray ( FixedArray< T > && other)
noexcept

Definition at line 157 of file fixed_array.hpp.

◆ ~FixedArray()

template<class T >
utils::FixedArray< T >::~FixedArray ( )

Definition at line 169 of file fixed_array.hpp.

◆ FixedArray() [3/3]

template<class T >
template<class GeneratorFunc >
utils::FixedArray< T >::FixedArray ( impl::GenerateTag ,
std::size_t size,
GeneratorFunc && generator )

Definition at line 134 of file fixed_array.hpp.

Member Function Documentation

◆ back() [1/2]

template<class T >
const T & utils::FixedArray< T >::back ( ) const
inlinenoexcept

Definition at line 70 of file fixed_array.hpp.

◆ back() [2/2]

template<class T >
T & utils::FixedArray< T >::back ( )
inlinenoexcept

Definition at line 69 of file fixed_array.hpp.

◆ begin() [1/2]

template<class T >
const T * utils::FixedArray< T >::begin ( ) const
inlinenoexcept

Definition at line 77 of file fixed_array.hpp.

◆ begin() [2/2]

template<class T >
T * utils::FixedArray< T >::begin ( )
inlinenoexcept

Definition at line 75 of file fixed_array.hpp.

◆ cbegin()

template<class T >
const T * utils::FixedArray< T >::cbegin ( ) const
inlinenoexcept

Definition at line 79 of file fixed_array.hpp.

◆ cend()

template<class T >
const T * utils::FixedArray< T >::cend ( ) const
inlinenoexcept

Definition at line 80 of file fixed_array.hpp.

◆ data() [1/2]

template<class T >
const T * utils::FixedArray< T >::data ( ) const
inlinenoexcept

Definition at line 73 of file fixed_array.hpp.

◆ data() [2/2]

template<class T >
T * utils::FixedArray< T >::data ( )
inlinenoexcept

Definition at line 72 of file fixed_array.hpp.

◆ empty()

template<class T >
bool utils::FixedArray< T >::empty ( ) const
inlinenoexcept

Definition at line 54 of file fixed_array.hpp.

◆ end() [1/2]

template<class T >
const T * utils::FixedArray< T >::end ( ) const
inlinenoexcept

Definition at line 78 of file fixed_array.hpp.

◆ end() [2/2]

template<class T >
T * utils::FixedArray< T >::end ( )
inlinenoexcept

Definition at line 76 of file fixed_array.hpp.

◆ front() [1/2]

template<class T >
const T & utils::FixedArray< T >::front ( ) const
inlinenoexcept

Definition at line 67 of file fixed_array.hpp.

◆ front() [2/2]

template<class T >
T & utils::FixedArray< T >::front ( )
inlinenoexcept

Definition at line 66 of file fixed_array.hpp.

◆ operator=()

template<class T >
FixedArray< T > & utils::FixedArray< T >::operator= ( FixedArray< T > && other)
noexcept

Definition at line 162 of file fixed_array.hpp.

◆ operator[]() [1/2]

template<class T >
const T & utils::FixedArray< T >::operator[] ( std::size_t i) const
inlinenoexcept

Definition at line 56 of file fixed_array.hpp.

◆ operator[]() [2/2]

template<class T >
T & utils::FixedArray< T >::operator[] ( std::size_t i)
inlinenoexcept

Definition at line 61 of file fixed_array.hpp.

◆ size()

template<class T >
std::size_t utils::FixedArray< T >::size ( ) const
inlinenoexcept

Definition at line 53 of file fixed_array.hpp.


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