4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt::container::index_map< T, A > Class Template Reference

Detailed Description

template<typename T, typename A = std::allocator<T>>
class fcppt::container::index_map< T, A >

An index-based container that grows on demand.

This container is a wrapper around a vector that grows on demand. If the container is accessed with an out-of-bounds index, it inserts a new element first. This is most useful with fcppt::optional::object.

Template Parameters
TThe element type.
AThe allocator type.

Public Types

using internal_type = std::vector<T, A>
 
using size_type = typename internal_type::size_type
 
using reference = typename internal_type::reference
 
using insert_function = fcppt::function<T()>
 

Public Member Functions

 index_map ()
 
reference get (size_type index, insert_function const &insert)
 Returns the element at an index or inserts new ones using a function.
 
reference operator[] (size_type index)
 Returns the element at an index or inserts new default-constructed one.
 
internal_type const & impl () const
 

Member Typedef Documentation

◆ insert_function

template<typename T , typename A = std::allocator<T>>
using fcppt::container::index_map< T, A >::insert_function = fcppt::function<T()>

◆ internal_type

template<typename T , typename A = std::allocator<T>>
using fcppt::container::index_map< T, A >::internal_type = std::vector<T, A>

◆ reference

template<typename T , typename A = std::allocator<T>>
using fcppt::container::index_map< T, A >::reference = typename internal_type::reference

◆ size_type

template<typename T , typename A = std::allocator<T>>
using fcppt::container::index_map< T, A >::size_type = typename internal_type::size_type

Constructor & Destructor Documentation

◆ index_map()

template<typename T , typename A = std::allocator<T>>
fcppt::container::index_map< T, A >::index_map ( )

Member Function Documentation

◆ get()

template<typename T , typename A = std::allocator<T>>
reference fcppt::container::index_map< T, A >::get ( size_type index,
insert_function const & insert )
nodiscard

Returns the element at an index or inserts new ones using a function.

Returns the element at index. If there is no such element, the result of insert() is inserted. Note that insert might be called multiple times.

◆ impl()

template<typename T , typename A = std::allocator<T>>
internal_type const & fcppt::container::index_map< T, A >::impl ( ) const
nodiscard

◆ operator[]()

template<typename T , typename A = std::allocator<T>>
reference fcppt::container::index_map< T, A >::operator[] ( size_type index)
nodiscard

Returns the element at an index or inserts new default-constructed one.

Returns the element at index. If there is no such element, T() is inserted.