2.8.0
Freundlich's C++ toolkit
Classes | Modules | Typedefs | Functions
fcppt.container

Description

Various containers and utility functions.

Classes

class  fcppt::container::dynamic_array< T, A >
 An array of dynamic size that does not initialize. More...
 
class  fcppt::container::get_or_insert_result< Reference >
 The result type of fcppt::container::get_or_insert_with_result. More...
 
class  fcppt::container::index_map< T, A >
 An index-based container that grows on demand. More...
 
class  fcppt::container::move_range< Container >
 A range that moves its elements. More...
 

Modules

 fcppt.container.array
 Functions for std::array
 
 fcppt.container.bitfield
 A statically sized bitfield.
 
 fcppt.container.buffer
 A special buffer class for uninitialized memory.
 
 fcppt.container.grid
 A simple n-dimensional array.
 
 fcppt.container.raw_vector
 A container for POD types that can be initialized from a buffer.
 
 fcppt.container.tree
 A tree data structure.
 
 fcppt.container.tuple
 Functions for std::tuple
 

Typedefs

template<typename Range >
using fcppt::container::size_result_type = std::make_unsigned_t< decltype(fcppt::container::detail::size(std::declval< Range >())) >
 The size type of a range. More...
 
template<typename Container >
using fcppt::container::to_iterator_type = std::conditional_t< std::is_const< Container >::value, typename Container::const_iterator, typename Container::iterator >
 Gets the iterator type of a container. More...
 
template<typename Container >
using fcppt::container::to_mapped_type = std::conditional_t< std::is_const< Container >::value, typename Container::mapped_type const, typename Container::mapped_type >
 Gets the mapped type of an associative container. More...
 
template<typename Container >
using fcppt::container::to_pointer_type = std::conditional_t< std::is_const< Container >::value, typename Container::const_pointer, typename Container::pointer >
 Gets the pointer type of a container. More...
 
template<typename Container >
using fcppt::container::to_reference_type = std::conditional_t< std::is_const< Container >::value, typename Container::const_reference, typename Container::reference >
 Gets the reference type of a container. More...
 
template<typename Container >
using fcppt::container::to_value_type = std::conditional_t< std::is_const< Container >::value, fcppt::type_traits::value_type< Container > const, fcppt::type_traits::value_type< Container > >
 The value type of a container depending on its constness. More...
 

Functions

template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::at_optional (Container &_container, typename Container::size_type const _index)
 Returns an element as an optional at a given position. More...
 
template<typename Container >
fcppt::container::to_pointer_type< Container > fcppt::container::data (Container &_container)
 Returns a pointer the beginning of a random access container. More...
 
template<typename Container >
fcppt::container::to_pointer_type< Container > fcppt::container::data_end (Container &_container)
 Returns a pointer one past the end of a random-access container> More...
 
template<typename Container , typename Key >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::find_opt (Container &_container, Key const &_key)
 Returns an element from a find operation or an empty optional. More...
 
template<typename Container , typename Key >
fcppt::optional::object< fcppt::container::to_iterator_type< Container >> fcppt::container::find_opt_iterator (Container &_container, Key const &_key)
 Returns an iterator from a find operation or an empty optional. More...
 
template<typename Container , typename Key >
fcppt::optional::object< fcppt::reference< fcppt::container::to_mapped_type< Container > >> fcppt::container::find_opt_mapped (Container &_container, Key const &_key)
 Returns an element from a find operation or an empty optional. More...
 
template<typename Container , typename Create >
Container::mapped_type & fcppt::container::get_or_insert (Container &_container, typename Container::key_type const &_key, Create const &_create)
 Gets from or inserts an element into a map. More...
 
template<typename Container , typename Create >
fcppt::container::get_or_insert_result< typename Container::mapped_type & > fcppt::container::get_or_insert_with_result (Container &_container, typename Container::key_type const &_key, Create const &_create)
 Gets from or inserts an element into a map and returns if it was inserted. More...
 
template<typename Container , typename Value >
bool fcppt::container::insert (Container &_container, Value &&_value)
 Inserts into an associative container. More...
 
template<typename Container , typename... Args>
Container fcppt::container::make (Args &&... _args)
 Creates a container from variadic arguments by moving. More...
 
template<typename Container >
fcppt::container::move_range< std::remove_reference_t< Container >> fcppt::container::make_move_range (Container &&_container)
 Creates a move range from a container. More...
 
template<typename Result , typename Map >
Result fcppt::container::map_values_copy (Map const &_map)
 Copies the mapped values of an associative container into a container. More...
 
template<typename Result , typename Map >
Result fcppt::container::map_values_ref (Map &_map)
 Maps the mapped values of an associative container to a container of references. More...
 
template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::maybe_back (Container &_container)
 Returns the back of a container as an optional. More...
 
template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::maybe_front (Container &_container)
 Returns the front of a container as an optional. More...
 
template<typename Container >
fcppt::container::detail::output< Container > fcppt::container::output (Container const &_container) noexcept
 Creates a class that has an output operator to print a container. More...
 
template<typename Container >
fcppt::optional::object< fcppt::container::to_value_type< Container >> fcppt::container::pop_back (Container &_container)
 Pops the back of a container as an optional. More...
 
template<typename Container >
fcppt::optional::object< fcppt::container::to_value_type< Container >> fcppt::container::pop_front (Container &_container)
 Pops the front of a container as an optional. More...
 
template<typename Range >
fcppt::container::size_result_type< Range > fcppt::container::size (Range const &_range)
 The size of a range. More...
 

Typedef Documentation

◆ size_result_type

template<typename Range >
using fcppt::container::size_result_type = typedef std::make_unsigned_t< decltype( fcppt::container::detail::size( std::declval< Range >() ) ) >

The size type of a range.

This type is always unsigned.

◆ to_iterator_type

template<typename Container >
using fcppt::container::to_iterator_type = typedef std::conditional_t< std::is_const< Container >::value, typename Container::const_iterator, typename Container::iterator >

Gets the iterator type of a container.

If Container is const, the result is Container::const_iterator. Otherwise, it is Container::iterator.

Template Parameters
ContainerA range type.

◆ to_mapped_type

template<typename Container >
using fcppt::container::to_mapped_type = typedef std::conditional_t< std::is_const< Container >::value, typename Container::mapped_type const, typename Container::mapped_type >

Gets the mapped type of an associative container.

If Container is const, the result is Container::mapped_type const. Otherwise, it is Container::mapped_type.

Template Parameters
ContainerAn associative container.

◆ to_pointer_type

template<typename Container >
using fcppt::container::to_pointer_type = typedef std::conditional_t< std::is_const< Container >::value, typename Container::const_pointer, typename Container::pointer >

Gets the pointer type of a container.

If Container is const, the result is Container::const_pointer. Otherwise, it is Container::pointer.

Template Parameters
ContainerA range type.

◆ to_reference_type

template<typename Container >
using fcppt::container::to_reference_type = typedef std::conditional_t< std::is_const< Container >::value, typename Container::const_reference, typename Container::reference >

Gets the reference type of a container.

If Container is const, the result is Container::const_reference. Otherwise, it is Container::reference.

Template Parameters
ContainerA range type.

◆ to_value_type

template<typename Container >
using fcppt::container::to_value_type = typedef std::conditional_t< std::is_const< Container >::value, fcppt::type_traits::value_type< Container > const, fcppt::type_traits::value_type< Container > >

The value type of a container depending on its constness.

If Container is const, the result is Container::value_type const. Otherwise, it is Container::value_type.

Template Parameters
ContainerA range type.

Function Documentation

◆ at_optional()

template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::at_optional ( Container &  _container,
typename Container::size_type const  _index 
)

Returns an element as an optional at a given position.

If _index is in the range of _container, the element at _index is returned. Otherwise, the result is the empty optional.

Template Parameters
ContainerMust be a random-access container.

◆ data()

template<typename Container >
fcppt::container::to_pointer_type< Container> fcppt::container::data ( Container &  _container)

Returns a pointer the beginning of a random access container.

Returns a pointer the beginning of _container, or the null pointer if _container is empty.

Template Parameters
ContainerMust be a random-access container.

◆ data_end()

template<typename Container >
fcppt::container::to_pointer_type< Container> fcppt::container::data_end ( Container &  _container)

Returns a pointer one past the end of a random-access container>

Returns a pointer to one past the end of _container, or the null pointer if _container is empty.

Template Parameters
ContainerMust be a random-access container.

◆ find_opt()

template<typename Container , typename Key >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::find_opt ( Container &  _container,
Key const &  _key 
)
inline

Returns an element from a find operation or an empty optional.

Searches for _key in the associative container _container. If _key is found, the corresponding mapped type is returned. Otherwise, the empty optional is returned.

Template Parameters
ContainerMust be an associative container.
KeyMust be a key that can be searched for.

◆ find_opt_iterator()

template<typename Container , typename Key >
fcppt::optional::object< fcppt::container::to_iterator_type< Container >> fcppt::container::find_opt_iterator ( Container &  _container,
Key const &  _key 
)

Returns an iterator from a find operation or an empty optional.

Searches for _key in the associative container _container. If _key is found, its iterator is returned. Otherwise, the empty optional is returned.

Template Parameters
ContainerMust be an associative container.
KeyMust be a key that can be searched for.

◆ find_opt_mapped()

template<typename Container , typename Key >
fcppt::optional::object< fcppt::reference< fcppt::container::to_mapped_type< Container > >> fcppt::container::find_opt_mapped ( Container &  _container,
Key const &  _key 
)
inline

Returns an element from a find operation or an empty optional.

Searches for _key in the associative container _container. If _key is found, the corresponding mapped object is returned. Otherwise, the empty optional is returned.

Template Parameters
ContainerMust be an associative container.
KeyMust be a key that can be searched for.

◆ get_or_insert()

template<typename Container , typename Create >
Container::mapped_type& fcppt::container::get_or_insert ( Container &  _container,
typename Container::key_type const &  _key,
Create const &  _create 
)
inline

Gets from or inserts an element into a map.

Tries to find _key in _container. If the mapped object is found, it is returned. Otherwise, _create is called with _a key to create a new mapped object which is then inserted into _container and returned.

Template Parameters
ContainerAn associative container.
CreateA function of type Container::mapped_type (Container::key_type).

◆ get_or_insert_with_result()

template<typename Container , typename Create >
fcppt::container::get_or_insert_result< typename Container::mapped_type &> fcppt::container::get_or_insert_with_result ( Container &  _container,
typename Container::key_type const &  _key,
Create const &  _create 
)

Gets from or inserts an element into a map and returns if it was inserted.

Tries to find _key in _container. If the mapped object is found, it is returned and inserted is true. Otherwise, _create is called with _a key to create a new mapped object which is then inserted into _container and returned along with inserted as false.

Template Parameters
ContainerAn associative container>
CreateA function of type Container::mapped_type (Container::key_type).

◆ insert()

template<typename Container , typename Value >
bool fcppt::container::insert ( Container &  _container,
Value &&  _value 
)

Inserts into an associative container.

Template Parameters
ContainerAn associative container.
ValueThe container's value_type.
Returns
Whether the value was inserted.

◆ make()

template<typename Container , typename... Args>
Container fcppt::container::make ( Args &&...  _args)
inline

Creates a container from variadic arguments by moving.

◆ make_move_range()

template<typename Container >
fcppt::container::move_range< std::remove_reference_t< Container >> fcppt::container::make_move_range ( Container &&  _container)
inline

Creates a move range from a container.

Parameters
_containerMust be an rvalue reference to a container.
Template Parameters
ContainerA container type.

◆ map_values_copy()

template<typename Result , typename Map >
Result fcppt::container::map_values_copy ( Map const &  _map)

Copies the mapped values of an associative container into a container.

Template Parameters
ResultA sequence container of Map::mapped_type.
MapAn associative container.

◆ map_values_ref()

template<typename Result , typename Map >
Result fcppt::container::map_values_ref ( Map &  _map)

Maps the mapped values of an associative container to a container of references.

Template Parameters
ResultA sequence container of fcppt::reference<Map::mapped_type> or fcppt::reference<Map::mapped_type const>.
MapAn associative container.

◆ maybe_back()

template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::maybe_back ( Container &  _container)

Returns the back of a container as an optional.

◆ maybe_front()

template<typename Container >
fcppt::optional::reference< fcppt::container::to_value_type< Container >> fcppt::container::maybe_front ( Container &  _container)

Returns the front of a container as an optional.

◆ output()

template<typename Container >
fcppt::container::detail::output< Container> fcppt::container::output ( Container const &  _container)
inlinenoexcept

Creates a class that has an output operator to print a container.

Template Parameters
ContainerMust be a container that has at least a forward iterator.

◆ pop_back()

template<typename Container >
fcppt::optional::object< fcppt::container::to_value_type< Container >> fcppt::container::pop_back ( Container &  _container)

Pops the back of a container as an optional.

◆ pop_front()

template<typename Container >
fcppt::optional::object< fcppt::container::to_value_type< Container >> fcppt::container::pop_front ( Container &  _container)

Pops the front of a container as an optional.

◆ size()

template<typename Range >
fcppt::container::size_result_type< Range> fcppt::container::size ( Range const &  _range)
inline

The size of a range.

Uses size() if possible, otherwise calculates the distance from begin to end.

Template Parameters
RangeMust be a range that either has begin/end or size and size_type.