4.4.1
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
Typedefs | Functions
fcppt.array

Description

Like std::array but with a proper constructor.

Typedefs

template<typename T >
using fcppt::array::is_object = typename fcppt::array::detail::is_object< T >::type
 Tests whether a type is a array.
 
template<typename Array , typename = std::enable_if_t<fcppt::array::is_object<Array>::value>>
using fcppt::array::value_type = fcppt::type_traits::value_type< Array >
 The value type of an array.
 

Functions

template<typename Array1 , typename Array2 , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Array2>>, std::is_same< fcppt::array::value_type<std::remove_cvref_t<Array1>>, fcppt::array::value_type<std::remove_cvref_t<Array2>>>>>>
fcppt::array::object< fcppt::array::value_type< std::remove_cvref_t< Array1 > >, fcppt::array::size< std::remove_cvref_t< Array1 > >::value+fcppt::array::size< std::remove_cvref_t< Array2 > >::value > fcppt::array::append (Array1 &&_array1, Array2 &&_array2)
 Appends two arrays.
 
template<typename Function , typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Arrays>>..., std::is_same< fcppt::array::size<std::remove_cvref_t<Array1>>, fcppt::array::size<std::remove_cvref_t<Arrays>>>...>>>
auto fcppt::array::apply (Function const &_function, Array1 &&_array1, Arrays &&..._arrays) -> fcppt::array::object< decltype(_function(fcppt::move_if_rvalue< Array1 >(std::declval< fcppt::container::to_reference_type< std::remove_reference_t< Array1 > > >()), fcppt::move_if_rvalue< Arrays >(std::declval< fcppt::container::to_reference_type< std::remove_reference_t< Arrays > > >())...)), fcppt::array::size< std::remove_cvref_t< Array1 > >::value >
 Applies a function to each tuple of elements of multiple arrays and returns an array containing the results.
 
template<typename T , std::size_t Size>
bool fcppt::array::operator== (fcppt::array::object< T, Size > const &a, fcppt::array::object< T, Size > const &b)
 Compares two arrays for equality.
 
template<std::size_t I, typename T , std::size_t Size, typename = std::enable_if_t<std::less<>{}(I, Size)>>
constexpr Tfcppt::array::get (fcppt::array::object< T, Size > &_value) noexcept
 Returns the I'th element of a nonconst array.
 
template<std::size_t I, typename T , std::size_t Size, typename = std::enable_if_t<std::less<>{}(I, Size)>>
constexpr T constfcppt::array::get (fcppt::array::object< T, Size > const &_value) noexcept
 Returns the I'th element of a const array.
 
template<typename Array , typename Function , typename = std::enable_if_t<fcppt::array::is_object<Array>::value>>
Array fcppt::array::init (Function const &_function)
 Constructs an array by calling a function with static indices.
 
template<typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Arrays>>..., std::is_same< fcppt::array::value_type<std::remove_cvref_t<Array1>>, fcppt::array::value_type<std::remove_cvref_t<Arrays>>>...>>>
fcppt::array::object< fcppt::array::value_type< std::remove_cvref_t< Array1 > >, fcppt::mpl::list::fold< fcppt::mpl::list::object< std::remove_cvref_t< Arrays >... >, fcppt::mpl::bind< fcppt::mpl::lambda< fcppt::mpl::add >, fcppt::mpl::bind< fcppt::mpl::lambda< fcppt::array::size >, fcppt::mpl::arg< 1 > >, fcppt::mpl::arg< 2 > >, fcppt::array::size< std::remove_cvref_t< Array1 > > >::value > fcppt::array::join (Array1 &&_array1, Arrays &&..._arrays)
 Appends multiple arrays.
 
template<typename Arg1 , typename... Args, typename = std::enable_if_t<std::conjunction_v<std::is_same< std::remove_cvref_t<Arg1>, std::remove_cvref_t<Args>>...>>>
fcppt::array::object< std::remove_cvref_t< Arg1 >, sizeof...(Args)+1Ufcppt::array::make (Arg1 &&_arg1, Args &&..._args)
 Make an array out of a parameter pack.
 
template<typename Array , typename Function , typename = std::enable_if_t< fcppt::array::is_object<std::remove_cvref_t<Array>>::value>>
auto fcppt::array::map (Array &&_source, Function const &_function) -> fcppt::array::object< decltype(_function(fcppt::move_if_rvalue< Array >(std::declval< fcppt::container::to_reference_type< std::remove_reference_t< Array > > >()))), fcppt::array::size< std::remove_cvref_t< Array > >::value >
 Applies a function to every element of an array and returns an array of the results.
 
template<typename Ch , typename Traits , typename Type , std::size_t Size>
std::basic_ostream< Ch, Traits > & fcppt::array::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::array::object< Type, Size > const &_array)
 Outputs an array to a stream.
 
template<typename Source , typename NewElement , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Source>>, std::is_same< std::remove_cvref_t<NewElement>, fcppt::array::value_type<std::remove_cvref_t<Source>>>>>>
fcppt::array::object< fcppt::type_traits::value_type< std::remove_cvref_t< Source > >, fcppt::array::size< std::remove_cvref_t< Source > >::value+1Ufcppt::array::push_back (Source &&_source, NewElement &&_new_element)
 Pushes a new element to the back of an array.
 

Typedef Documentation

◆ is_object

template<typename T >
using fcppt::array::is_object = typedef typename fcppt::array::detail::is_object<T>::type

Tests whether a type is a array.

◆ value_type

template<typename Array , typename = std::enable_if_t<fcppt::array::is_object<Array>::value>>
using fcppt::array::value_type = typedef fcppt::type_traits::value_type<Array>

The value type of an array.

Function Documentation

◆ append()

template<typename Array1 , typename Array2 , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Array2>>, std::is_same< fcppt::array::value_type<std::remove_cvref_t<Array1>>, fcppt::array::value_type<std::remove_cvref_t<Array2>>>>>>
fcppt::array::object< fcppt::array::value_type< std::remove_cvref_t< Array1 > >, fcppt::array::size< std::remove_cvref_t< Array1 > >::value+ fcppt::array::size< std::remove_cvref_t< Array2 > >::value > fcppt::array::append ( Array1 &&  _array1,
Array2 &&  _array2 
)

Appends two arrays.

Let _array1 = [x_1, ..., x_n] and _array2 = [y_1, ..., y_m]. The result is [x_1, ..., x_n, y_1, ..., y_m].

Both arrays must have the same value type.

◆ apply()

template<typename Function , typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Arrays>>..., std::is_same< fcppt::array::size<std::remove_cvref_t<Array1>>, fcppt::array::size<std::remove_cvref_t<Arrays>>>...>>>
auto fcppt::array::apply ( Function const _function,
Array1 &&  _array1,
Arrays &&...  _arrays 
) -> fcppt::array::object< decltype(_function( fcppt::move_if_rvalue<Array1>(std::declval<fcppt::container::to_reference_type< std::remove_reference_t<Array1>>>()), fcppt::move_if_rvalue<Arrays>(std::declval<fcppt::container::to_reference_type< std::remove_reference_t<Arrays>>>())...)), fcppt::array::size<std::remove_cvref_t<Array1>>::value>

Applies a function to each tuple of elements of multiple arrays and returns an array containing the results.

Calls _function(e, e_1, ..., e_n) for every e of _array1 and e_1, ..., e_n of _arrays.

Template Parameters
FunctionMust be a function callable as R (Array1::value_type, Arrays::value_type...), where R is the result type.

◆ get() [1/2]

template<std::size_t I, typename T , std::size_t Size, typename = std::enable_if_t<std::less<>{}(I, Size)>>
constexpr T & fcppt::array::get ( fcppt::array::object< T, Size > &  _value)
inlineconstexprnoexcept

Returns the I'th element of a nonconst array.

◆ get() [2/2]

template<std::size_t I, typename T , std::size_t Size, typename = std::enable_if_t<std::less<>{}(I, Size)>>
constexpr T const & fcppt::array::get ( fcppt::array::object< T, Size > const _value)
inlineconstexprnoexcept

Returns the I'th element of a const array.

◆ init()

template<typename Array , typename Function , typename = std::enable_if_t<fcppt::array::is_object<Array>::value>>
Array fcppt::array::init ( Function const &  _function)
inline

Constructs an array by calling a function with static indices.

Constructs an array of type Array by calling _function(std::integral_constant<std::size_t, Index>) for every index.

Template Parameters
FunctionMust be a function callable as Array::value_type (std::integral_constant<std::size_t, I>).

◆ join()

template<typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Array1>>, fcppt::array::is_object<std::remove_cvref_t<Arrays>>..., std::is_same< fcppt::array::value_type<std::remove_cvref_t<Array1>>, fcppt::array::value_type<std::remove_cvref_t<Arrays>>>...>>>
fcppt::array::object< fcppt::array::value_type< std::remove_cvref_t< Array1 > >, fcppt::mpl::list::fold< fcppt::mpl::list::object< std::remove_cvref_t< Arrays >... >, fcppt::mpl::bind< fcppt::mpl::lambda< fcppt::mpl::add >, fcppt::mpl::bind< fcppt::mpl::lambda< fcppt::array::size >, fcppt::mpl::arg< 1 > >, fcppt::mpl::arg< 2 > >, fcppt::array::size< std::remove_cvref_t< Array1 > > >::value > fcppt::array::join ( Array1 &&  _array1,
Arrays &&...  _arrays 
)

Appends multiple arrays.

Let a_1 = Array1 and Arrays = a_2, ..., a_n. The result is equivalent to append(a_1, ..., append(a_{n-1}, a_n) ...).

All arrays must have the same value type.

See also
fcppt::array::append

◆ make()

template<typename Arg1 , typename... Args, typename = std::enable_if_t<std::conjunction_v<std::is_same< std::remove_cvref_t<Arg1>, std::remove_cvref_t<Args>>...>>>
fcppt::array::object< std::remove_cvref_t< Arg1 >, sizeof...(Args)+1U > fcppt::array::make ( Arg1 &&  _arg1,
Args &&...  _args 
)
inline

Make an array out of a parameter pack.

Let _args be (a_1,...,a_n). All elements of _args must be of the same type T. The result is fcppt::array::object<T,n>{a_1,...,a_n}.

Template Parameters
ArgsA parameter pack t_1,...,t_n such that remove_cv_ref<t_1> = ... = remove_cv_ref<t_n>.

◆ map()

template<typename Array , typename Function , typename = std::enable_if_t< fcppt::array::is_object<std::remove_cvref_t<Array>>::value>>
auto fcppt::array::map ( Array &&  _source,
Function const _function 
) -> fcppt::array::object< decltype(_function(fcppt::move_if_rvalue<Array>( std::declval<fcppt::container::to_reference_type<std::remove_reference_t<Array>>>()))), fcppt::array::size<std::remove_cvref_t<Array>>::value>
inline

Applies a function to every element of an array and returns an array of the results.

Calls _function(element) for every element of _source.

Example:

three_ints const a{1, 2, 3};
three_ints const b(fcppt::array::map(a, [](int const _arg) { return _arg * 3; }));
// b now contains: 3, 6, 9
Template Parameters
FunctionMust be a function callable as R (Array::value_type), where R is the result type.

◆ operator<<()

template<typename Ch , typename Traits , typename Type , std::size_t Size>
std::basic_ostream< Ch, Traits > & fcppt::array::operator<< ( std::basic_ostream< Ch, Traits > &  _stream,
fcppt::array::object< Type, Size > const _array 
)

Outputs an array to a stream.

◆ operator==()

template<typename T , std::size_t Size>
bool fcppt::array::operator== ( fcppt::array::object< T, Size > const a,
fcppt::array::object< T, Size > const b 
)
inline

Compares two arrays for equality.

◆ push_back()

template<typename Source , typename NewElement , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<std::remove_cvref_t<Source>>, std::is_same< std::remove_cvref_t<NewElement>, fcppt::array::value_type<std::remove_cvref_t<Source>>>>>>
fcppt::array::object< fcppt::type_traits::value_type< std::remove_cvref_t< Source > >, fcppt::array::size< std::remove_cvref_t< Source > >::value+1U > fcppt::array::push_back ( Source &&  _source,
NewElement &&  _new_element 
)

Pushes a new element to the back of an array.

Pushes _new_element to the back of _source.

Template Parameters
NewElementMust be the same as value_type<Source>