3.5.0
Freundlich's C++ toolkit
Typedefs | Functions
fcppt.metal

Description

Metal related helper functions and metafunctions.

Typedefs

template<template< typename ... > class Type, typename List >
using fcppt::metal::as = typename fcppt::metal::detail::as< Type, List >::type
 Turns a metal list into another type. More...
 
template<typename List >
using fcppt::metal::as_tuple = fcppt::metal::as< std::tuple, List >
 Turns a metal list into a tuple. More...
 
template<typename List , typename Value >
using fcppt::metal::contains = fcppt::type_traits::to_bool< ::metal::contains< List, Value > >
 Like metal::contains, but returning a boolean. More...
 
template<typename Map >
using fcppt::metal::flip_map = typename fcppt::metal::detail::flip_map< Map >::type
 Flips a metal map. More...
 
template<typename Pair >
using fcppt::metal::flip_pair = ::metal::pair< ::metal::second< Pair >, ::metal::first< Pair > >
 Flips a metal pair. More...
 
template<typename Dest , typename Number >
using fcppt::metal::from_number = typename fcppt::metal::detail::from_number< Dest, Number >::type
 Turns a metal::number into a std::integral_constant. More...
 
template<typename Result , typename List >
using fcppt::metal::from_number_list = ::metal::transform< ::metal::bind< ::metal::lambda< fcppt::metal::from_number >, ::metal::always< Result >, ::metal::_1 >, List >
 Converts a metal::list of metal::numbers into a metal::list of std::integral_constants. More...
 
template<typename Function >
using fcppt::metal::function_args = typename fcppt::metal::detail::function_args< Function >::type
 The argument types of a function as a metal::list. More...
 
template<typename List , typename Type >
using fcppt::metal::index_of = typename fcppt::metal::detail::index_of< List, Type >::type
 Returns the index of an element of a metal::list. More...
 
template<typename List , typename Pred >
using fcppt::metal::index_of_if = typename fcppt::metal::detail::index_of_if< List, Pred >::type
 Returns the index of an element of a metal::list that matches a predicate. More...
 
template<typename Type , Type Begin, Type End>
using fcppt::metal::interval = typename fcppt::metal::detail::interval< Type, Begin, End >::type
 Creates a list of std::integral_constants that form an interval. More...
 
template<typename List >
using fcppt::metal::is_set = std::is_same< ::metal::size< List >, fcppt::metal::set::size< fcppt::metal::set::from_list_relaxed< List > > >
 Checks if every element is unique in a metal::list. More...
 
template<typename Map1 , typename Map2 >
using fcppt::metal::maps_equal = fcppt::type_traits::to_bool< ::metal::invoke< ::metal::if_< ::metal::as_number< std::is_same< fcppt::metal::set::symmetric_difference< fcppt::metal::set::from_list_relaxed< ::metal::keys< Map1 > >, fcppt::metal::set::from_list_relaxed< ::metal::keys< Map2 > > >, fcppt::metal::set::make<> > >, ::metal::bind< ::metal::lambda< fcppt::metal::detail::map_same_values >, ::metal::always< Map1 >, ::metal::always< Map2 > >, ::metal::always< ::metal::false_ > > > >
 Checks if two metal::maps are equal. More...
 
template<typename Sequence >
using fcppt::metal::max_value = fcppt::metal::from_number< fcppt::type_traits::value_type< ::metal::front< Sequence > >, ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::lambda< ::metal::greater >, ::metal::_1, ::metal::_2 >, ::metal::_1, ::metal::_2 >, ::metal::front< fcppt::metal::to_number_list< Sequence > >, fcppt::metal::to_number_list< Sequence > > >
 Calculates the maximum value in a sequence. More...
 
template<typename Sequence >
using fcppt::metal::partial_sums = ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::append >, ::metal::_1, ::metal::bind< ::metal::lambda< ::metal::add >, ::metal::bind< ::metal::lambda< ::metal::back >, ::metal::_1 >, ::metal::_2 > >, ::metal::list< ::metal::number< 0 > >, Sequence >
 Calculates a new sequence that consists of the sums of the old sequence. More...
 
template<typename Set1 , typename Set2 >
using fcppt::metal::set::difference = ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::bind< ::metal::lambda< fcppt::metal::to_number >, ::metal::lambda< fcppt::metal::set::contains > >, ::metal::always< Set2 >, ::metal::_2 >, ::metal::_1, ::metal::bind< ::metal::lambda< fcppt::metal::set::insert >, ::metal::_1, ::metal::_2 > >, fcppt::metal::set::make<>, fcppt::metal::set::to_list< Set1 > >
 The difference of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::metal::set::intersection = ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::bind< ::metal::lambda< fcppt::metal::to_number >, ::metal::lambda< fcppt::metal::set::contains > >, ::metal::always< Set2 >, ::metal::_2 >, ::metal::bind< ::metal::lambda< fcppt::metal::set::insert_relaxed >, ::metal::_1, ::metal::_2 >, ::metal::_1 >, fcppt::metal::set::make<>, fcppt::metal::set::to_list< Set1 > >
 The intersection of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::metal::set::symmetric_difference = fcppt::metal::set::union_< fcppt::metal::set::difference< Set1, Set2 >, fcppt::metal::set::difference< Set2, Set1 > >
 The symmetric difference of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::metal::set::union_ = ::metal::accumulate< ::metal::bind< ::metal::lambda< fcppt::metal::set::insert_relaxed >, ::metal::_1, ::metal::_2 >, Set1, fcppt::metal::set::to_list< Set2 > >
 The union of two sets. More...
 
template<typename Src >
using fcppt::metal::to_number = fcppt::type_traits::safe_integral_cast< ::metal::int_, Src >
 Converts a std::integral_constant to a metal::number. More...
 
template<typename List >
using fcppt::metal::to_number_list = ::metal::transform< ::metal::lambda< fcppt::metal::to_number >, List >
 Converts a metal::list of std::integral_constants into a metal::list of metal::numbers. More...
 

Functions

template<typename Sequence , typename Function >
void fcppt::metal::for_each_break (Function const &_function)
 Invoke a function on each element of a sequence while giving the ability to break out of the loop. More...
 
template<typename Sequence , typename Index , typename Function , typename FailFunction >
decltype(auto) FCPPT_PP_PUSH_WARNING fcppt::metal::invoke_on (Index const &_index, Function const &_function, FailFunction const &_fail_function)
 Applies a function to the nth element of a sequence with a runtime index. More...
 
template<typename Sequence >
fcppt::io::ostreamfcppt::metal::print (fcppt::io::ostream &_stream)
 Pretty prints a metal list. More...
 
template<typename Sequence >
fcppt::string fcppt::metal::sequence_to_string ()
 Converts a sequence to a string. More...
 

Typedef Documentation

◆ as

template<template< typename ... > class Type, typename List >
using fcppt::metal::as = typedef typename fcppt::metal::detail::as< Type, List >::type

Turns a metal list into another type.

For List=metal::list<t_1,...,t_n> the result type is Type<t_1,...,t_n>.

Template Parameters
ListMust be a metal::list.

◆ as_tuple

template<typename List >
using fcppt::metal::as_tuple = typedef fcppt::metal::as< std::tuple, List >

Turns a metal list into a tuple.

For List=metal::list<t_1,...,t_n> the result type is std::tuple<t_1,...,t_n>.

Template Parameters
ListMust be a metal::list.

◆ contains

template<typename List , typename Value >
using fcppt::metal::contains = typedef fcppt::type_traits::to_bool< ::metal::contains< List, Value > >

Like metal::contains, but returning a boolean.

◆ difference

template<typename Set1 , typename Set2 >
using fcppt::metal::set::difference = typedef ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::bind< ::metal::lambda< fcppt::metal::to_number >, ::metal::lambda< fcppt::metal::set::contains > >, ::metal::always< Set2 >, ::metal::_2 >, ::metal::_1, ::metal::bind< ::metal::lambda< fcppt::metal::set::insert >, ::metal::_1, ::metal::_2 > >, fcppt::metal::set::make<>, fcppt::metal::set::to_list< Set1 > >

The difference of two sets.

The result contains every element that is in Set1, but not in Set2.

Template Parameters
Set1Must be a metal set.
Set2Must be a metal set.

◆ flip_map

template<typename Map >
using fcppt::metal::flip_map = typedef typename fcppt::metal::detail::flip_map< Map >::type

Flips a metal map.

For each element of Map, swaps the key and the value type. For this to work, the mapped types of the map must all be different ypes.

Template Parameters
MapA metal::map.

◆ flip_pair

template<typename Pair >
using fcppt::metal::flip_pair = typedef ::metal::pair< ::metal::second< Pair >, ::metal::first< Pair > >

Flips a metal pair.

Swaps first and second of Pair.

Template Parameters
PairMust be a metal::pair.

◆ from_number

template<typename Dest , typename Number >
using fcppt::metal::from_number = typedef typename fcppt::metal::detail::from_number< Dest, Number >::type

Turns a metal::number into a std::integral_constant.

Let Number=metal::number<n>. The result will be std::integral_constant<Dest,n>. This only works if n can be converted without loss into Dest.

Template Parameters
DestMust be an integral type.
NumberMust be a metal::number.

◆ from_number_list

template<typename Result , typename List >
using fcppt::metal::from_number_list = typedef ::metal::transform< ::metal::bind< ::metal::lambda< fcppt::metal::from_number >, ::metal::always< Result >, ::metal::_1 >, List >

Converts a metal::list of metal::numbers into a metal::list of std::integral_constants.

Applies fcppt::metal::from_number<Result,_> to each element of the list.

Template Parameters
ResultMust be an integral type.
ListMust be a metal::list of metal::numbers.

◆ function_args

template<typename Function >
using fcppt::metal::function_args = typedef typename fcppt::metal::detail::function_args< Function >::type

The argument types of a function as a metal::list.

Template Parameters
FunctionMust be a function type.

◆ index_of

template<typename List , typename Type >
using fcppt::metal::index_of = typedef typename fcppt::metal::detail::index_of< List, Type >::type

Returns the index of an element of a metal::list.

Similar to metal::find but asserts that the element is actually in the list.

Template Parameters
ListMust be a metal::list.

◆ index_of_if

template<typename List , typename Pred >
using fcppt::metal::index_of_if = typedef typename fcppt::metal::detail::index_of_if< List, Pred >::type

Returns the index of an element of a metal::list that matches a predicate.

Similar to metal::find_if but asserts that the element is actually in the list.

Template Parameters
ListMust be a metal::list.

◆ intersection

template<typename Set1 , typename Set2 >
using fcppt::metal::set::intersection = typedef ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::bind< ::metal::lambda< fcppt::metal::to_number >, ::metal::lambda< fcppt::metal::set::contains > >, ::metal::always< Set2 >, ::metal::_2 >, ::metal::bind< ::metal::lambda< fcppt::metal::set::insert_relaxed >, ::metal::_1, ::metal::_2 >, ::metal::_1 >, fcppt::metal::set::make<>, fcppt::metal::set::to_list< Set1 > >

The intersection of two sets.

The result contains every element that is both in Set1 and Set2.

Template Parameters
Set1Must be a metal set.
Set2Must be a metal set.

◆ interval

template<typename Type , Type Begin, Type End>
using fcppt::metal::interval = typedef typename fcppt::metal::detail::interval< Type, Begin, End >::type

Creates a list of std::integral_constants that form an interval.

Returns metal::list<std::integral_constant<Type,Begin>, ..., std::integral_constant<Type,End-1>>.

Template Parameters
TypeMust be an integral type.

◆ is_set

template<typename List >
using fcppt::metal::is_set = typedef std::is_same< ::metal::size< List >, fcppt::metal::set::size< fcppt::metal::set::from_list_relaxed< List > > >

Checks if every element is unique in a metal::list.

Template Parameters
ListMust be a metal::list.

◆ maps_equal

template<typename Map1 , typename Map2 >
using fcppt::metal::maps_equal = typedef fcppt::type_traits::to_bool< ::metal::invoke< ::metal::if_< ::metal::as_number< std::is_same< fcppt::metal::set::symmetric_difference< fcppt::metal::set::from_list_relaxed< ::metal::keys< Map1 > >, fcppt::metal::set::from_list_relaxed< ::metal::keys< Map2 > > >, fcppt::metal::set::make<> > >, ::metal::bind< ::metal::lambda< fcppt::metal::detail::map_same_values >, ::metal::always< Map1 >, ::metal::always< Map2 > >, ::metal::always< ::metal::false_ > > > >

Checks if two metal::maps are equal.

Two maps are equal if and only if they contain the same key-value pairs. The order in which they occur does not matter.

Template Parameters
Map1Must be a metal::map.
Map2Must be a metal::map.

◆ max_value

template<typename Sequence >
using fcppt::metal::max_value = typedef fcppt::metal::from_number< fcppt::type_traits::value_type< ::metal::front< Sequence > >, ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::lambda< ::metal::greater >, ::metal::_1, ::metal::_2 >, ::metal::_1, ::metal::_2 >, ::metal::front< fcppt::metal::to_number_list< Sequence > >, fcppt::metal::to_number_list< Sequence > > >

Calculates the maximum value in a sequence.

Calculates the maximum value in Sequence.

// Calculate the maximum size of all the types
using
types
=
metal::list<
short, // NOLINT(google-runtime-int)
int, // NOLINT(google-runtime-int)
long // NOLINT(google-runtime-int)
>;
template<
typename Type
>
using
sizeof_
=
std::integral_constant<
std::size_t,
sizeof(Type)
>;
using
=
metal::transform<
metal::lambda<
sizeof_
>,
types
>
>;
static_assert(
std::is_same_v<
sizeof_<
long // NOLINT(google-runtime-int)
>
>
);
Template Parameters
SequenceA non empty metal::list of std::integral_constants.

◆ partial_sums

template<typename Sequence >
using fcppt::metal::partial_sums = typedef ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::append >, ::metal::_1, ::metal::bind< ::metal::lambda< ::metal::add >, ::metal::bind< ::metal::lambda< ::metal::back >, ::metal::_1 >, ::metal::_2 > >, ::metal::list< ::metal::number< 0 > >, Sequence >

Calculates a new sequence that consists of the sums of the old sequence.

For the integral constants (c_1, ..., c_n) in Sequence, the resulting sequence will consist of the values (0, c_1, c_1 + c_2, ..., c_1 + ... c_n).

Template Parameters
SequenceA metal::list of metal::numbers.

◆ symmetric_difference

template<typename Set1 , typename Set2 >
using fcppt::metal::set::symmetric_difference = typedef fcppt::metal::set::union_< fcppt::metal::set::difference< Set1, Set2 >, fcppt::metal::set::difference< Set2, Set1 > >

The symmetric difference of two sets.

The result contains every element that is either in Set1 or in Set2, but not in both.

Template Parameters
Set1Must be a metal set.
Set2Must be a metal set.

◆ to_number

template<typename Src >
using fcppt::metal::to_number = typedef fcppt::type_traits::safe_integral_cast< ::metal::int_, Src >

Converts a std::integral_constant to a metal::number.

Let Src=std::integral_constant<T,n>. The result will be metal::number<n>. This only works if n can be converted without loss.

Template Parameters
SrcMust be a std::integral_constant.

◆ to_number_list

template<typename List >
using fcppt::metal::to_number_list = typedef ::metal::transform< ::metal::lambda< fcppt::metal::to_number >, List >

Converts a metal::list of std::integral_constants into a metal::list of metal::numbers.

Applies fcppt::metal::to_number to each element of the list.

Template Parameters
ListMust be a metal::list of std::integral_constants.

◆ union_

template<typename Set1 , typename Set2 >
using fcppt::metal::set::union_ = typedef ::metal::accumulate< ::metal::bind< ::metal::lambda< fcppt::metal::set::insert_relaxed >, ::metal::_1, ::metal::_2 >, Set1, fcppt::metal::set::to_list< Set2 > >

The union of two sets.

The result contains every element that is in Set1 or in Set2.

Template Parameters
Set1Must be a metal set.
Set2Must be a metal set.

Function Documentation

◆ for_each_break()

template<typename Sequence , typename Function >
void fcppt::metal::for_each_break ( Function const &  _function)
inline

Invoke a function on each element of a sequence while giving the ability to break out of the loop.

Template Parameters
SequenceMust be a metal::list.
FunctionA polymorphic function callable as fcppt::loop (fcppt::tag<T>) for every T in Sequence.

◆ invoke_on()

template<typename Sequence , typename Index , typename Function , typename FailFunction >
decltype( auto ) FCPPT_PP_PUSH_WARNING fcppt::metal::invoke_on ( Index const &  _index,
Function const &  _function,
FailFunction const &  _fail_function 
)

Applies a function to the nth element of a sequence with a runtime index.

Let Sequence be the types (t_0,...,t_{n-1}) and i = _index. If i is less than n, the result is _function called with fcppt::tag<t_i>. Otherwise, the result of _fail_function is returned.

Note
The compile time and the runtime complexities of this function are linear in the size of the metal sequence.
// In the following example, we are going to create a function that can
// transform a color type given at runtime (defined via an enum) into a static
// color type (represented by variant over static color types).
#include <fcppt/tag.hpp>
#include <fcppt/assert/error.hpp>
#include <fcppt/cast/enum_to_underlying.hpp>
#include <fcppt/cast/to_unsigned.hpp>
#include <fcppt/metal/invoke_on.hpp>
#include <fcppt/variant/from_list.hpp>
#include <fcppt/variant/holds_type.hpp>
#include <fcppt/config/external_begin.hpp>
#include <metal.hpp>
#include <exception>
#include <fcppt/config/external_end.hpp>
namespace
{
// Our color enum
enum class color_enum
{
bgr,
rgb
// + more color types
};
// Our static color types
struct bgr
{
};
struct rgb
{
};
// Typedef the available static color types
using
static_color_types
=
metal::list<
bgr,
rgb
>;
// The variant type that can hold any of the static color types
using
color_variant
=
static_color_types
>;
// Transforms a concrete color type into a color_variant. This function will be
// used with invoke_on.
struct create_function
{
template<
typename ConcreteColor
>
color_variant
operator()(
ConcreteColor
>
) const
{
return
color_variant(
ConcreteColor()
);
}
};
// Transforms a color enum into a static color type using invoke_on
color_variant
make_color_variant(
color_enum const _value
)
{
return
static_color_types
>(
_value
)
),
create_function(),
[]()
-> color_variant
{
std::terminate();
}
);
}
}
int
main()
{
color_variant const variant(
make_color_variant(
color_enum::rgb
)
);
rgb
>(
variant
)
);
}
Template Parameters
SequenceA metal::list.
IndexAn unsigned type.
FunctionMust be callable as R fcppt::tag<T>() for every T in Sequence, where R is the result type.
FailFunctionMust be a callable as R (), where R is the result tye.

◆ print()

template<typename Sequence >
fcppt::io::ostream& fcppt::metal::print ( fcppt::io::ostream _stream)

Pretty prints a metal list.

Pretty prints Sequence to _stream. Every type in Sequence will be converted to a string using fcppt::type_name. The resulting format of the printed sequence will be (name_1, ..., name_n).

Template Parameters
SequenceMust be a metal::list.
Parameters
_streamThe stream to print to.
Returns
_stream

◆ sequence_to_string()

template<typename Sequence >
fcppt::string fcppt::metal::sequence_to_string ( )

Converts a sequence to a string.

Template Parameters
SequenceMust be a metal sequence.
fcppt::options::result
fcppt::either::object< fcppt::options::error, T > result
The result of a parse operation.
Definition: result_fwd.hpp:35
fcppt::variant::from_list
fcppt::metal::as< fcppt::variant::object, Types > from_list
Declares a variant using a metal::list.
Definition: from_list_fwd.hpp:35
fcppt::tag
A value for a type name.
Definition: tag.hpp:26
fcppt::metal::max_value
fcppt::metal::from_number< fcppt::type_traits::value_type< ::metal::front< Sequence > >, ::metal::accumulate< ::metal::bind< ::metal::lambda< ::metal::if_ >, ::metal::bind< ::metal::lambda< ::metal::greater >, ::metal::_1, ::metal::_2 >, ::metal::_1, ::metal::_2 >, ::metal::front< fcppt::metal::to_number_list< Sequence > >, fcppt::metal::to_number_list< Sequence > > > max_value
Calculates the maximum value in a sequence.
Definition: max_value.hpp:70
fcppt::cast::enum_to_underlying
constexpr std::underlying_type_t< Enum > enum_to_underlying(Enum const _enum) noexcept
Converts an enum to its underlying type.
Definition: enum_to_underlying.hpp:37
fcppt::variant::holds_type
bool holds_type(fcppt::variant::object< Elements... > const &_variant)
Checks if a type is held by a variant.
Definition: holds_type.hpp:49
fcppt::cast::to_unsigned
constexpr std::make_unsigned_t< Type > to_unsigned(Type const _value) noexcept
Converts a signed int to its unsigned type.
Definition: to_unsigned.hpp:38
fcppt::metal::invoke_on
decltype(auto) FCPPT_PP_PUSH_WARNING invoke_on(Index const &_index, Function const &_function, FailFunction const &_fail_function)
Applies a function to the nth element of a sequence with a runtime index.
Definition: invoke_on.hpp:65
FCPPT_ASSERT_ERROR
#define FCPPT_ASSERT_ERROR(condition)
Asserts a condition in the middle of a function.
Definition: error.hpp:23