|
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).
|
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. | |
| Iterable & | operator= (const Iterable &other) |
| Copy assignment. | |
| Iterable & | operator= (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. | |
Wrapper that adds a uniform iteration and mutation API around a standard container.
| Container | Underlying 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)).
| using StormByte::Iterable< Container >::const_iterator = ConstIterator |
Const adapter.
| using StormByte::Iterable< Container >::const_pointer = typename Container::const_pointer |
Container::const_pointer.
| using StormByte::Iterable< Container >::const_reference = typename Container::const_reference |
Container::const_reference.
| using StormByte::Iterable< Container >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Const reverse adapter.
| using StormByte::Iterable< Container >::difference_type = typename Container::difference_type |
Container::difference_type.
| using StormByte::Iterable< Container >::iterator = Iterator |
Mutable adapter.
| using StormByte::Iterable< Container >::pointer = typename Container::pointer |
Container::pointer.
| using StormByte::Iterable< Container >::reference = typename Container::reference |
Container::reference.
| using StormByte::Iterable< Container >::reverse_iterator = std::reverse_iterator<iterator> |
Mutable reverse adapter.
| using StormByte::Iterable< Container >::size_type = typename Container::size_type |
Container::size_type.
| using StormByte::Iterable< Container >::value_type = typename Container::value_type |
Container::value_type.
|
default |
Empty iterable.
|
explicit |
Builds from a container.
| C | Deduced container type (lvalue or rvalue of Container). |
| data | Container 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.
| StormByte::Iterable< Container >::Iterable | ( | const Iterable< Container > & | other | ) |
Copy constructor.
| other | Source iterable. |
| StormByte::Exception | If 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.
|
default |
Move constructor.
|
virtualdefault |
Destructor.
| void StormByte::Iterable< Container >::add | ( | T && | value | ) |
Inserts value via push_back, else push_front, else associative insert.
| T | Deduced argument type (lvalue or rvalue of value_type). |
| value | Element 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.
| void StormByte::Iterable< Container >::add | ( | value_type | value | ) |
Inserts a temporary / braced value.
| value | Element constructed at the call site, then moved. |
Needed because a forwarding reference cannot deduce from a braced-init-list (add({"k", v})).
|
noexcept |
Const begin.
|
noexcept |
Mutable begin.
|
noexcept |
Const begin.
|
noexcept |
Const end.
|
noexcept |
Const reverse begin.
|
noexcept |
Const reverse end.
|
noexcept |
Whether the container is empty.
|
noexcept |
Const end.
|
noexcept |
Mutable end.
| bool StormByte::Iterable< Container >::has_item | ( | const value_type & | value | ) | const |
Linear search for an equal element.
| value | Value to find. |
true if found. | bool StormByte::Iterable< Container >::has_item | ( | M const & | value | ) | const |
Linear search over mapped values.
| M | Comparable to Container::mapped_type. |
| value | Mapped value to find. |
true if any mapped value equals value. | bool StormByte::Iterable< Container >::has_key | ( | const K & | key | ) | const |
Key lookup for associative containers.
| K | Convertible to Container::key_type. |
| key | Key to find. |
true if key is present. | bool StormByte::Iterable< Container >::operator!= | ( | const Iterable< Container > & | other | ) | const |
Inequality of the underlying containers.
| other | Other iterable. |
| Iterable & StormByte::Iterable< Container >::operator= | ( | const Iterable< Container > & | other | ) |
Copy assignment.
| other | Source iterable. |
*this. | StormByte::Exception | If Container is not copy-assignable. |
|
default |
Move assignment.
*this. | bool StormByte::Iterable< Container >::operator== | ( | const Iterable< Container > & | other | ) | const |
Equality of the underlying containers.
| other | Other iterable. |
| auto StormByte::Iterable< Container >::operator[] | ( | K const & | key | ) | -> decltype(auto) |
Mutable key access for associative containers.
| K | Convertible to Container::key_type. |
| key | Key to look up or insert. |
Container::operator[]). | auto StormByte::Iterable< Container >::operator[] | ( | K const & | key | ) | const -> decltype(auto) |
Const key access for associative containers.
| K | Convertible to Container::key_type. |
| key | Key to look up. |
| OutOfBoundsError | If key is missing. |
| reference StormByte::Iterable< Container >::operator[] | ( | size_type | i | ) |
Zero-based mutable index access.
| i | Index. |
i. | OutOfBoundsError | If i is not less than size(). |
Uses Container::operator[] when Type::HasSubscript holds; otherwise advances iterators.
| const_reference StormByte::Iterable< Container >::operator[] | ( | size_type | i | ) | const |
Zero-based const index access.
| i | Index. |
i. | OutOfBoundsError | If i is not less than size(). |
|
noexcept |
Const reverse begin.
|
noexcept |
Mutable reverse begin.
|
noexcept |
Const reverse end.
|
noexcept |
Mutable reverse end.
|
noexcept |
Element count.
|
protected |
Underlying container.