ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::FixedVector< T > Class Template Reference

Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avoids std::vector template overhead (_M_realloc_insert, _M_default_append) when size is known at initialization but not at compile time. More...

#include <helpers.h>

Public Member Functions

 FixedVector ()=default
 
 FixedVector (std::initializer_list< T > init_list)
 Constructor from initializer list - allocates exact size needed This enables brace initialization: FixedVector<int> v = {1, 2, 3};.
 
 ~FixedVector ()
 
 FixedVector (const FixedVector &)=delete
 
FixedVector & operator= (const FixedVector &)=delete
 
 FixedVector (FixedVector &&other) noexcept
 
 operator std::vector< T > () const
 
FixedVector & operator= (FixedVector &&other) noexcept
 
FixedVector & operator= (std::initializer_list< T > init_list)
 Assignment from initializer list - avoids temporary and move overhead This enables: FixedVector<int> v; v = {1, 2, 3};.
 
void init (size_t n)
 
bool try_init (size_t n)
 
void clear ()
 
void release ()
 
void push_back (const T &value)
 Add element without bounds checking Caller must ensure sufficient capacity was allocated via init() Silently ignores pushes beyond capacity (no exception or assertion)
 
void push_back (T &&value)
 Add element by move without bounds checking Caller must ensure sufficient capacity was allocated via init() Silently ignores pushes beyond capacity (no exception or assertion)
 
template<typename... Args>
T & emplace_back (Args &&...args)
 Emplace element without bounds checking - constructs in-place with arguments Caller must ensure sufficient capacity was allocated via init() Returns reference to the newly constructed element NOTE: Caller MUST ensure size_ < capacity_ before calling.
 
T & front ()
 Access first element (no bounds checking - matches std::vector behavior) Caller must ensure vector is not empty (size() > 0)
 
const T & front () const
 
T & back ()
 Access last element (no bounds checking - matches std::vector behavior) Caller must ensure vector is not empty (size() > 0)
 
const T & back () const
 
void pop_back ()
 Remove the last element in place (no reallocation, keeps capacity) Caller must ensure vector is not empty (size() > 0)
 
size_t size () const
 
bool empty () const
 
size_t capacity () const
 
bool full () const
 
T & operator[] (size_t i)
 Access element without bounds checking (matches std::vector behavior) Caller must ensure index is valid (i < size())
 
const T & operator[] (size_t i) const
 
T & at (size_t i)
 Access element with bounds checking (matches std::vector behavior) Note: No exception thrown on out of bounds - caller must ensure index is valid.
 
const T & at (size_t i) const
 
T * begin ()
 
T * end ()
 
const T * begin () const
 
const T * end () const
 

Detailed Description

template<typename T>
class esphome::FixedVector< T >

Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avoids std::vector template overhead (_M_realloc_insert, _M_default_append) when size is known at initialization but not at compile time.

Definition at line 624 of file helpers.h.

Constructor & Destructor Documentation

◆ FixedVector() [1/4]

template<typename T >
esphome::FixedVector< T >::FixedVector ( )
default

◆ FixedVector() [2/4]

template<typename T >
esphome::FixedVector< T >::FixedVector ( std::initializer_list< T > init_list)
inline

Constructor from initializer list - allocates exact size needed This enables brace initialization: FixedVector<int> v = {1, 2, 3};.

Definition at line 671 of file helpers.h.

◆ ~FixedVector()

template<typename T >
esphome::FixedVector< T >::~FixedVector ( )
inline

Definition at line 673 of file helpers.h.

◆ FixedVector() [3/4]

template<typename T >
esphome::FixedVector< T >::FixedVector ( const FixedVector< T > & )
delete

◆ FixedVector() [4/4]

template<typename T >
esphome::FixedVector< T >::FixedVector ( FixedVector< T > && other)
inlinenoexcept

Definition at line 680 of file helpers.h.

Member Function Documentation

◆ at() [1/2]

template<typename T >
T & esphome::FixedVector< T >::at ( size_t i)
inline

Access element with bounds checking (matches std::vector behavior) Note: No exception thrown on out of bounds - caller must ensure index is valid.

Definition at line 812 of file helpers.h.

◆ at() [2/2]

template<typename T >
const T & esphome::FixedVector< T >::at ( size_t i) const
inline

Definition at line 813 of file helpers.h.

◆ back() [1/2]

template<typename T >
T & esphome::FixedVector< T >::back ( )
inline

Access last element (no bounds checking - matches std::vector behavior) Caller must ensure vector is not empty (size() > 0)

Definition at line 788 of file helpers.h.

◆ back() [2/2]

template<typename T >
const T & esphome::FixedVector< T >::back ( ) const
inline

Definition at line 789 of file helpers.h.

◆ begin() [1/2]

template<typename T >
T * esphome::FixedVector< T >::begin ( )
inline

Definition at line 816 of file helpers.h.

◆ begin() [2/2]

template<typename T >
const T * esphome::FixedVector< T >::begin ( ) const
inline

Definition at line 818 of file helpers.h.

◆ capacity()

template<typename T >
size_t esphome::FixedVector< T >::capacity ( ) const
inline

Definition at line 802 of file helpers.h.

◆ clear()

template<typename T >
void esphome::FixedVector< T >::clear ( )
inline

Definition at line 737 of file helpers.h.

◆ emplace_back()

template<typename T >
template<typename... Args>
T & esphome::FixedVector< T >::emplace_back ( Args &&... args)
inline

Emplace element without bounds checking - constructs in-place with arguments Caller must ensure sufficient capacity was allocated via init() Returns reference to the newly constructed element NOTE: Caller MUST ensure size_ < capacity_ before calling.

Definition at line 774 of file helpers.h.

◆ empty()

template<typename T >
bool esphome::FixedVector< T >::empty ( ) const
inline

Definition at line 801 of file helpers.h.

◆ end() [1/2]

template<typename T >
T * esphome::FixedVector< T >::end ( )
inline

Definition at line 817 of file helpers.h.

◆ end() [2/2]

template<typename T >
const T * esphome::FixedVector< T >::end ( ) const
inline

Definition at line 819 of file helpers.h.

◆ front() [1/2]

template<typename T >
T & esphome::FixedVector< T >::front ( )
inline

Access first element (no bounds checking - matches std::vector behavior) Caller must ensure vector is not empty (size() > 0)

Definition at line 783 of file helpers.h.

◆ front() [2/2]

template<typename T >
const T & esphome::FixedVector< T >::front ( ) const
inline

Definition at line 784 of file helpers.h.

◆ full()

template<typename T >
bool esphome::FixedVector< T >::full ( ) const
inline

Definition at line 803 of file helpers.h.

◆ init()

template<typename T >
void esphome::FixedVector< T >::init ( size_t n)
inline

Definition at line 714 of file helpers.h.

◆ operator std::vector< T >()

template<typename T >
esphome::FixedVector< T >::operator std::vector< T > ( ) const
inline

Definition at line 685 of file helpers.h.

◆ operator=() [1/3]

template<typename T >
FixedVector & esphome::FixedVector< T >::operator= ( const FixedVector< T > & )
delete

◆ operator=() [2/3]

template<typename T >
FixedVector & esphome::FixedVector< T >::operator= ( FixedVector< T > && other)
inlinenoexcept

Definition at line 687 of file helpers.h.

◆ operator=() [3/3]

template<typename T >
FixedVector & esphome::FixedVector< T >::operator= ( std::initializer_list< T > init_list)
inline

Assignment from initializer list - avoids temporary and move overhead This enables: FixedVector<int> v; v = {1, 2, 3};.

Definition at line 703 of file helpers.h.

◆ operator[]() [1/2]

template<typename T >
T & esphome::FixedVector< T >::operator[] ( size_t i)
inline

Access element without bounds checking (matches std::vector behavior) Caller must ensure index is valid (i < size())

Definition at line 807 of file helpers.h.

◆ operator[]() [2/2]

template<typename T >
const T & esphome::FixedVector< T >::operator[] ( size_t i) const
inline

Definition at line 808 of file helpers.h.

◆ pop_back()

template<typename T >
void esphome::FixedVector< T >::pop_back ( )
inline

Remove the last element in place (no reallocation, keeps capacity) Caller must ensure vector is not empty (size() > 0)

Definition at line 793 of file helpers.h.

◆ push_back() [1/2]

template<typename T >
void esphome::FixedVector< T >::push_back ( const T & value)
inline

Add element without bounds checking Caller must ensure sufficient capacity was allocated via init() Silently ignores pushes beyond capacity (no exception or assertion)

Definition at line 751 of file helpers.h.

◆ push_back() [2/2]

template<typename T >
void esphome::FixedVector< T >::push_back ( T && value)
inline

Add element by move without bounds checking Caller must ensure sufficient capacity was allocated via init() Silently ignores pushes beyond capacity (no exception or assertion)

Definition at line 762 of file helpers.h.

◆ release()

template<typename T >
void esphome::FixedVector< T >::release ( )
inline

Definition at line 743 of file helpers.h.

◆ size()

template<typename T >
size_t esphome::FixedVector< T >::size ( ) const
inline

Definition at line 800 of file helpers.h.

◆ try_init()

template<typename T >
bool esphome::FixedVector< T >::try_init ( size_t n)
inline

Definition at line 720 of file helpers.h.


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