StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
StormByte::Iterable< Container > Class Template Reference

Wrapper that adds a uniform iteration and mutation API around a standard container. More...

#include <StormByte/iterable.hxx>

Classes

class  ConstIterator
 Const iterator adapter over Container::const_iterator. More...
 
class  Iterator
 Mutable iterator adapter over Container::iterator. More...
 

Public Types

using value_type = typename Container::value_type
 Container::value_type.
 
using size_type = typename Container::size_type
 Container::size_type.
 
using difference_type = typename Container::difference_type
 Container::difference_type.
 
using reference = typename Container::reference
 Container::reference.
 
using const_reference = typename Container::const_reference
 Container::const_reference.
 
using pointer = typename Container::pointer
 Container::pointer.
 
using const_pointer = typename Container::const_pointer
 Container::const_pointer.
 
using iterator = Iterator
 Mutable adapter.
 
using const_iterator = ConstIterator
 Const adapter.
 
using reverse_iterator = std::reverse_iterator< iterator >
 Mutable reverse adapter.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 Const reverse adapter.
 

Public Member Functions

 Iterable ()=default
 Empty iterable.
 
template<typename C >
requires Type::SameAs<C, Container> && ( (Type::LvalueReference<C> && Type::CopyConstructible<value_type>) || (!Type::LvalueReference<C> && Type::MoveConstructible<value_type>) )
 Iterable (C &&data)
 Builds from a container.
 
 Iterable (const Iterable &other)
 Copy constructor.
 
 Iterable (Iterable &&)=default
 Move constructor.
 
virtual ~Iterable ()=default
 Destructor.
 
Iterableoperator= (const Iterable &other)
 Copy assignment.
 
Iterableoperator= (Iterable &&)=default
 Move assignment.
 
bool operator== (const Iterable &other) const
 Equality of the underlying containers.
 
bool operator!= (const Iterable &other) const
 Inequality of the underlying containers.
 
iterator begin () noexcept
 Mutable begin.
 
const_iterator begin () const noexcept
 Const begin.
 
iterator end () noexcept
 Mutable end.
 
const_iterator end () const noexcept
 Const end.
 
const_iterator cbegin () const noexcept
 Const begin.
 
const_iterator cend () const noexcept
 Const end.
 
reverse_iterator rbegin () noexcept
 Mutable reverse begin.
 
reverse_iterator rend () noexcept
 Mutable reverse end.
 
const_reverse_iterator rbegin () const noexcept
 Const reverse begin.
 
const_reverse_iterator rend () const noexcept
 Const reverse end.
 
const_reverse_iterator crbegin () const noexcept
 Const reverse begin.
 
const_reverse_iterator crend () const noexcept
 Const reverse end.
 
size_type size () const noexcept
 Element count.
 
bool empty () const noexcept
 Whether the container is empty.
 
reference operator[] (size_type i)
 Zero-based mutable index access.
 
template<typename K >
requires (Type::HasMappedType<Container>)
auto operator[] (K const &key) -> decltype(auto)
 Mutable key access for associative containers.
 
template<typename K >
requires (Type::HasMappedType<const Container>)
auto operator[] (K const &key) const -> decltype(auto)
 Const key access for associative containers.
 
const_reference operator[] (size_type i) const
 Zero-based const index access.
 
template<typename T >
requires ( (Type::LvalueReference<T> && Type::CopyConstructible<value_type>) || (!Type::LvalueReference<T> && Type::MoveConstructible<value_type>) )
void add (T &&value)
 Inserts value via push_back, else push_front, else associative insert.
 
void add (value_type value)
 Inserts a temporary / braced value.
 
bool has_item (const value_type &value) const
 Linear search for an equal element.
 
template<typename M >
requires Type::HasMappedType<const Container> && std::convertible_to<M, typename Container::mapped_type>
bool has_item (M const &value) const
 Linear search over mapped values.
 
template<typename K >
requires Type::HasMappedType<const Container>
bool has_key (const K &key) const
 Key lookup for associative containers.
 

Protected Attributes

Container m_data
 Underlying container.
 

Detailed Description

template<typename Container>
class StormByte::Iterable< Container >

Wrapper that adds a uniform iteration and mutation API around a standard container.

Template Parameters
ContainerUnderlying container (std::vector, std::map, std::deque, …).

Iterator adapters, size/empty, subscript (index or key) and add() chosen by Type concepts (push_back, push_front or associative insert).

Insertion and index subscript use one definition with if constexpr so MSVC STL and clang-cl do not instantiate unsupported APIs or emit duplicate symbols under the MSVC ABI.

Constraints use the template parameter Container directly (not decltype(m_data)).

Member Typedef Documentation

◆ const_iterator

template<typename Container >
using StormByte::Iterable< Container >::const_iterator = ConstIterator

Const adapter.

◆ const_pointer

template<typename Container >
using StormByte::Iterable< Container >::const_pointer = typename Container::const_pointer

Container::const_pointer.

◆ const_reference

template<typename Container >
using StormByte::Iterable< Container >::const_reference = typename Container::const_reference

Container::const_reference.

◆ const_reverse_iterator

template<typename Container >
using StormByte::Iterable< Container >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Const reverse adapter.

◆ difference_type

template<typename Container >
using StormByte::Iterable< Container >::difference_type = typename Container::difference_type

Container::difference_type.

◆ iterator

template<typename Container >
using StormByte::Iterable< Container >::iterator = Iterator

Mutable adapter.

◆ pointer

template<typename Container >
using StormByte::Iterable< Container >::pointer = typename Container::pointer

Container::pointer.

◆ reference

template<typename Container >
using StormByte::Iterable< Container >::reference = typename Container::reference

Container::reference.

◆ reverse_iterator

template<typename Container >
using StormByte::Iterable< Container >::reverse_iterator = std::reverse_iterator<iterator>

Mutable reverse adapter.

◆ size_type

template<typename Container >
using StormByte::Iterable< Container >::size_type = typename Container::size_type

Container::size_type.

◆ value_type

template<typename Container >
using StormByte::Iterable< Container >::value_type = typename Container::value_type

Container::value_type.

Constructor & Destructor Documentation

◆ Iterable() [1/4]

template<typename Container >
StormByte::Iterable< Container >::Iterable ( )
default

Empty iterable.

◆ Iterable() [2/4]

template<typename Container >
template<typename C >
requires Type::SameAs<C, Container> && ( (Type::LvalueReference<C> && Type::CopyConstructible<value_type>) || (!Type::LvalueReference<C> && Type::MoveConstructible<value_type>) )
StormByte::Iterable< Container >::Iterable ( C &&  data)
explicit

Builds from a container.

Template Parameters
CDeduced container type (lvalue or rvalue of Container).
Parameters
dataContainer to take. Lvalues are copied; rvalues are moved.

One function template so clang-cl / MSVC STL do not instantiate a copy of vector<unique_ptr<T>>. An lvalue requires Type::CopyConstructible on value_type; an rvalue requires Type::MoveConstructible. Constrained to Container so this constructor does not hide Iterable copy / move.

◆ Iterable() [3/4]

template<typename Container >
StormByte::Iterable< Container >::Iterable ( const Iterable< Container > &  other)

Copy constructor.

Parameters
otherSource iterable.
Exceptions
StormByte::ExceptionIf Container is not copy-constructible.

Always declared so clang-cl / MSVC can export a derived class. The vector copy is behind if constexpr; a requires = default is still instantiated under dllexport.

◆ Iterable() [4/4]

template<typename Container >
StormByte::Iterable< Container >::Iterable ( Iterable< Container > &&  )
default

Move constructor.

◆ ~Iterable()

template<typename Container >
virtual StormByte::Iterable< Container >::~Iterable ( )
virtualdefault

Destructor.

Member Function Documentation

◆ add() [1/2]

template<typename Container >
template<typename T >
requires ( (Type::LvalueReference<T> && Type::CopyConstructible<value_type>) || (!Type::LvalueReference<T> && Type::MoveConstructible<value_type>) )
void StormByte::Iterable< Container >::add ( T &&  value)

Inserts value via push_back, else push_front, else associative insert.

Template Parameters
TDeduced argument type (lvalue or rvalue of value_type).
Parameters
valueElement to add. Lvalues are copied; rvalues are moved.

One function template so clang-cl / MSVC STL do not instantiate push_back(const unique_ptr&) when the container holds move-only values. An lvalue requires Type::CopyConstructible; an rvalue requires Type::MoveConstructible.

◆ add() [2/2]

template<typename Container >
void StormByte::Iterable< Container >::add ( value_type  value)

Inserts a temporary / braced value.

Parameters
valueElement constructed at the call site, then moved.

Needed because a forwarding reference cannot deduce from a braced-init-list (add({"k", v})).

◆ begin() [1/2]

template<typename Container >
const_iterator StormByte::Iterable< Container >::begin ( ) const
noexcept

Const begin.

◆ begin() [2/2]

template<typename Container >
iterator StormByte::Iterable< Container >::begin ( )
noexcept

Mutable begin.

◆ cbegin()

template<typename Container >
const_iterator StormByte::Iterable< Container >::cbegin ( ) const
noexcept

Const begin.

◆ cend()

template<typename Container >
const_iterator StormByte::Iterable< Container >::cend ( ) const
noexcept

Const end.

◆ crbegin()

template<typename Container >
const_reverse_iterator StormByte::Iterable< Container >::crbegin ( ) const
noexcept

Const reverse begin.

◆ crend()

template<typename Container >
const_reverse_iterator StormByte::Iterable< Container >::crend ( ) const
noexcept

Const reverse end.

◆ empty()

template<typename Container >
bool StormByte::Iterable< Container >::empty ( ) const
noexcept

Whether the container is empty.

◆ end() [1/2]

template<typename Container >
const_iterator StormByte::Iterable< Container >::end ( ) const
noexcept

Const end.

◆ end() [2/2]

template<typename Container >
iterator StormByte::Iterable< Container >::end ( )
noexcept

Mutable end.

◆ has_item() [1/2]

template<typename Container >
bool StormByte::Iterable< Container >::has_item ( const value_type value) const

Linear search for an equal element.

Parameters
valueValue to find.
Returns
true if found.

◆ has_item() [2/2]

template<typename Container >
template<typename M >
requires Type::HasMappedType<const Container> && std::convertible_to<M, typename Container::mapped_type>
bool StormByte::Iterable< Container >::has_item ( M const &  value) const

Linear search over mapped values.

Template Parameters
MComparable to Container::mapped_type.
Parameters
valueMapped value to find.
Returns
true if any mapped value equals value.

◆ has_key()

template<typename Container >
template<typename K >
requires Type::HasMappedType<const Container>
bool StormByte::Iterable< Container >::has_key ( const K &  key) const

Key lookup for associative containers.

Template Parameters
KConvertible to Container::key_type.
Parameters
keyKey to find.
Returns
true if key is present.

◆ operator!=()

template<typename Container >
bool StormByte::Iterable< Container >::operator!= ( const Iterable< Container > &  other) const

Inequality of the underlying containers.

Parameters
otherOther iterable.

◆ operator=() [1/2]

template<typename Container >
Iterable & StormByte::Iterable< Container >::operator= ( const Iterable< Container > &  other)

Copy assignment.

Parameters
otherSource iterable.
Returns
*this.
Exceptions
StormByte::ExceptionIf Container is not copy-assignable.

◆ operator=() [2/2]

template<typename Container >
Iterable & StormByte::Iterable< Container >::operator= ( Iterable< Container > &&  )
default

Move assignment.

Returns
*this.

◆ operator==()

template<typename Container >
bool StormByte::Iterable< Container >::operator== ( const Iterable< Container > &  other) const

Equality of the underlying containers.

Parameters
otherOther iterable.

◆ operator[]() [1/4]

template<typename Container >
template<typename K >
requires (Type::HasMappedType<Container>)
auto StormByte::Iterable< Container >::operator[] ( K const &  key) -> decltype(auto)

Mutable key access for associative containers.

Template Parameters
KConvertible to Container::key_type.
Parameters
keyKey to look up or insert.
Returns
Mapped value (Container::operator[]).

◆ operator[]() [2/4]

template<typename Container >
template<typename K >
requires (Type::HasMappedType<const Container>)
auto StormByte::Iterable< Container >::operator[] ( K const &  key) const -> decltype(auto)

Const key access for associative containers.

Template Parameters
KConvertible to Container::key_type.
Parameters
keyKey to look up.
Returns
Const mapped value.
Exceptions
OutOfBoundsErrorIf key is missing.

◆ operator[]() [3/4]

template<typename Container >
reference StormByte::Iterable< Container >::operator[] ( size_type  i)

Zero-based mutable index access.

Parameters
iIndex.
Returns
Reference to the element at i.
Exceptions
OutOfBoundsErrorIf i is not less than size().

Uses Container::operator[] when Type::HasSubscript holds; otherwise advances iterators.

◆ operator[]() [4/4]

template<typename Container >
const_reference StormByte::Iterable< Container >::operator[] ( size_type  i) const

Zero-based const index access.

Parameters
iIndex.
Returns
Const reference to the element at i.
Exceptions
OutOfBoundsErrorIf i is not less than size().

◆ rbegin() [1/2]

template<typename Container >
const_reverse_iterator StormByte::Iterable< Container >::rbegin ( ) const
noexcept

Const reverse begin.

◆ rbegin() [2/2]

template<typename Container >
reverse_iterator StormByte::Iterable< Container >::rbegin ( )
noexcept

Mutable reverse begin.

◆ rend() [1/2]

template<typename Container >
const_reverse_iterator StormByte::Iterable< Container >::rend ( ) const
noexcept

Const reverse end.

◆ rend() [2/2]

template<typename Container >
reverse_iterator StormByte::Iterable< Container >::rend ( )
noexcept

Mutable reverse end.

◆ size()

template<typename Container >
size_type StormByte::Iterable< Container >::size ( ) const
noexcept

Element count.

Member Data Documentation

◆ m_data

template<typename Container >
Container StormByte::Iterable< Container >::m_data
protected

Underlying container.


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