3.7.0
Freundlich's C++ toolkit
Typedefs | Functions
fcppt.array

Description

Like std::array but with 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. More...
 
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. More...
 

Functions

template<typename Array1 , typename Array2 , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Array2>>, std::is_same< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array2>>>>>>
fcppt::array::object< fcppt::array::value_type< fcppt::type_traits::remove_cv_ref_t< Array1 > >, fcppt::array::size< fcppt::type_traits::remove_cv_ref_t< Array1 > >::value+fcppt::array::size< fcppt::type_traits::remove_cv_ref_t< Array2 > >::value > fcppt::array::append (Array1 &&_array1, Array2 &&_array2)
 Appends two arrays. More...
 
template<typename Function , typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Arrays>>..., std::is_same< fcppt::array::size<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::size<fcppt::type_traits::remove_cv_ref_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< fcppt::type_traits::remove_cv_ref_t< Array1 >>::value >
 Applies a function to each tuple of elements of multiple arrays and returns an array containing the results. More...
 
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. More...
 
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) noexcept
 Returns the I'th element of a nonconst array. More...
 
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) noexcept
 Returns the I'th element of a const array. More...
 
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. More...
 
template<typename Array1 , typename... Arrays, typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Arrays>>..., std::is_same< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Arrays>>>...>>>
fcppt::array::object< fcppt::array::value_type< fcppt::type_traits::remove_cv_ref_t< Array1 > >, fcppt::metal::from_number< std::size_t, ::metal::accumulate< ::metal::bind< ::metal::lambda<::metal::add >, ::metal::bind< ::metal::lambda< fcppt::metal::to_number >, ::metal::bind<::metal::lambda< fcppt::array::size >, ::metal::_2 > >, ::metal::_1 >, fcppt::metal::to_number< fcppt::array::size< fcppt::type_traits::remove_cv_ref_t< Array1 > > >, ::metal::list< fcppt::type_traits::remove_cv_ref_t< Arrays >... > > >::value > fcppt::array::join (Array1 &&_array1, Arrays &&..._arrays)
 Appends multiple arrays. More...
 
template<typename Arg1 , typename... Args, typename = std::enable_if_t<std::conjunction_v<std::is_same< fcppt::type_traits::remove_cv_ref_t<Arg1>, fcppt::type_traits::remove_cv_ref_t<Args>>...>>>
fcppt::array::object< fcppt::type_traits::remove_cv_ref_t< Arg1 >, sizeof...(Args)+1U > fcppt::array::make (Arg1 &&_arg1, Args &&..._args)
 Make an array out of a parameter pack. More...
 
template<typename Array , typename Function , typename = std::enable_if_t< fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_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< fcppt::type_traits::remove_cv_ref_t< Array >>::value >
 Applies a function to every element of an array and returns an array of the results. More...
 
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. More...
 
template<typename Source , typename NewElement , typename = std::enable_if_t<std::conjunction_v< fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Source>>, std::is_same< fcppt::type_traits::remove_cv_ref_t<NewElement>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Source>>>>>>
fcppt::array::object< fcppt::type_traits::value_type< fcppt::type_traits::remove_cv_ref_t< Source > >, fcppt::array::size< fcppt::type_traits::remove_cv_ref_t< Source > >::value+1U > fcppt::array::push_back (Source &&_source, NewElement &&_new_element)
 Pushes a new element to the back of an array. More...
 

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<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Array2>>, std::is_same< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array2>>>>>>
fcppt::array::object< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1> >, fcppt::array::size<fcppt::type_traits::remove_cv_ref_t<Array1> >::value + fcppt::array::size<fcppt::type_traits::remove_cv_ref_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<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Arrays>>..., std::is_same< fcppt::array::size<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::size<fcppt::type_traits::remove_cv_ref_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<fcppt::type_traits::remove_cv_ref_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<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::is_object<fcppt::type_traits::remove_cv_ref_t<Arrays>>..., std::is_same< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1>>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Arrays>>>...>>>
fcppt::array::object< fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Array1> >, fcppt::metal::from_number< std::size_t, ::metal::accumulate< ::metal::bind< ::metal::lambda<::metal::add>, ::metal::bind< ::metal::lambda<fcppt::metal::to_number>, ::metal::bind<::metal::lambda<fcppt::array::size>, ::metal::_2> >, ::metal::_1>, fcppt::metal::to_number< fcppt::array::size<fcppt::type_traits::remove_cv_ref_t<Array1> > >, ::metal::list<fcppt::type_traits::remove_cv_ref_t<Arrays>...> > >::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< fcppt::type_traits::remove_cv_ref_t<Arg1>, fcppt::type_traits::remove_cv_ref_t<Args>>...>>>
fcppt::array::object<fcppt::type_traits::remove_cv_ref_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<fcppt::type_traits::remove_cv_ref_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<fcppt::type_traits::remove_cv_ref_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:

using three_ints = fcppt::array::object<int, 3>;
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<fcppt::type_traits::remove_cv_ref_t<Source>>, std::is_same< fcppt::type_traits::remove_cv_ref_t<NewElement>, fcppt::array::value_type<fcppt::type_traits::remove_cv_ref_t<Source>>>>>>
fcppt::array::object< fcppt::type_traits::value_type<fcppt::type_traits::remove_cv_ref_t<Source> >, fcppt::array::size<fcppt::type_traits::remove_cv_ref_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>