4.4.1
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
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.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.
 

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.
 
template<typename Container >
using fcppt::container::to_iterator_type = std::conditional_t< std::is_const_v< Container >, typename Container::const_iterator, typename Container::iterator >
 Gets the iterator type of a container.
 
template<typename Container >
using fcppt::container::to_mapped_type = std::conditional_t< std::is_const_v< Container >, typename Container::mapped_type const, typename Container::mapped_type >
 Gets the mapped type of an associative container.
 
template<typename Container >
using fcppt::container::to_pointer_type = std::conditional_t< std::is_const_v< Container >, typename Container::const_pointer, typename Container::pointer >
 Gets the pointer type of a container.
 
template<typename Container >
using fcppt::container::to_reference_type = std::conditional_t< std::is_const_v< Container >, typename Container::const_reference, typename Container::reference >
 Gets the reference type of a container.
 
template<typename Container >
using fcppt::container::to_value_type = std::conditional_t< std::is_const_v< Container >, fcppt::type_traits::value_type< Container > const, fcppt::type_traits::value_type< Container > >
 The value type of a container depending on its constness.
 

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.
 
template<typename Container >
fcppt::container::to_pointer_type< Container > fcppt::container::data (Container &_container)
 Returns a pointer to the beginning of a random access container.
 
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>
 
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.
 
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.
 
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.
 
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.
 
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.
 
template<typename Container , typename Value >
bool fcppt::container::insert (Container &_container, Value &&_value)
 Inserts into an associative container.
 
template<typename Container , typename... Args>
std::remove_cvref_t< Container > fcppt::container::join (Container &&_first, Args &&..._args)
 Joins two containers.
 
template<typename Set , typename Map >
Set fcppt::container::key_set (Map const &_map)
 Creates a set of keys from a map.
 
template<typename Container , typename... Args>
Container fcppt::container::make (Args &&..._args)
 Creates a container from variadic arguments by moving.
 
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.
 
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<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<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.
 
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.
 
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.
 
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.
 
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.
 
template<typename Set >
Set fcppt::container::set_difference (Set const &_a, Set const &_b)
 Returns the difference of two sets.
 
template<typename Set >
Set fcppt::container::set_intersection (Set const &_a, Set const &_b)
 Returns the intersection of two sets.
 
template<typename Set >
Set fcppt::container::set_union (Set const &_a, Set const &_b)
 Returns the union of two sets.
 
template<typename Range >
fcppt::container::size_result_type< Range > fcppt::container::size (Range const &_range)
 The size of a range.
 
template<typename Container >
fcppt::container::uncons_result< Container > fcppt::container::uncons (Container &_container)
 Splits a container into its head and tail.
 

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_v<Container>, 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_v<Container>, 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_v<Container>, 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_v<Container>, 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_v<Container>, 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 to the beginning of a random access container.

Returns a pointer to 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.

◆ join()

template<typename Container , typename... Args>
std::remove_cvref_t< Container > fcppt::container::join ( Container &&  _first,
Args &&...  _args 
)
inline

Joins two containers.

Joins containers _first and all containers from _args, by inserting the containers from _args into _first.

Parameters
_firstThe left container.
_argsThe other containers, which will be inserted into the left container.
Template Parameters
ContainerA container class that supports insert of iterator ranges.

◆ key_set()

template<typename Set , typename Map >
Set fcppt::container::key_set ( Map const &  _map)
inline

Creates a set of keys from a map.

Inserts every key from _map into the resulting set.

Template Parameters
MapA map-like container.
SetA set-like container.

◆ 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.

◆ set_difference()

template<typename Set >
Set fcppt::container::set_difference ( Set const &  _a,
Set const &  _b 
)

Returns the difference of two sets.

Template Parameters
SetMust be an associative container

◆ set_intersection()

template<typename Set >
Set fcppt::container::set_intersection ( Set const &  _a,
Set const &  _b 
)

Returns the intersection of two sets.

Template Parameters
SetMust be an associative container

◆ set_union()

template<typename Set >
Set fcppt::container::set_union ( Set const &  _a,
Set const &  _b 
)

Returns the union of two sets.

Template Parameters
SetMust be an associative container

◆ 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.

◆ uncons()

template<typename Container >
fcppt::container::uncons_result< Container > fcppt::container::uncons ( Container &  _container)

Splits a container into its head and tail.