2.10.0
Freundlich's C++ toolkit
Typedefs | Functions
fcppt.brigand

Description

Brigand related helper functions and metafunctions.

Typedefs

template<typename Sequence , typename Predicate >
using fcppt::brigand::all_of = typename fcppt::brigand::detail::all_of_impl< Sequence, Predicate >::type
 Checks if a predicate is true for every element. More...
 
template<typename Type , Type Dividend, Type Divisor>
using fcppt::brigand::ceil_div = typename fcppt::brigand::detail::ceil_div< Type, Dividend, Divisor >::type
 Calculates a division of integral contants rounded towards infinity. More...
 
template<typename Sequence1 , typename Sequence2 >
using fcppt::brigand::equal_to = ::brigand::all< ::brigand::transform< Sequence1, Sequence2, ::brigand::bind< ::brigand::apply, ::brigand::bind< ::brigand::equal_to, ::brigand::_1, ::brigand::_2 > > >, ::brigand::identity< ::brigand::_1 > >
 Checks if two sequences of integral constants are equal. More...
 
template<typename Map >
using fcppt::brigand::flip_map = ::brigand::transform< Map, ::brigand::bind< fcppt::brigand::flip_pair, ::brigand::_1 > >
 Flips a brigand map. More...
 
template<typename Pair >
using fcppt::brigand::flip_pair = ::brigand::pair< fcppt::brigand::pair_second< Pair >, fcppt::brigand::pair_first< Pair > >
 Flips a brigand pair. More...
 
template<typename Sequence , typename Type >
using fcppt::brigand::found_t = ::brigand::found< Sequence, ::brigand::bind< std::is_same, ::brigand::pin< Type >, ::brigand::_1 > >
 Checks if a sequence contains an element. More...
 
template<typename Left , typename Right >
using fcppt::brigand::implication = ::brigand::or_< ::brigand::not_< Left >, Right >
 The implication function: Left -> Right. More...
 
template<typename IntegralType , typename Conv , typename Integral >
using fcppt::brigand::integral_cast = std::integral_constant< IntegralType, fcppt::brigand::detail::integral_cast_value< IntegralType, Conv, Integral >::value >
 Does an integral cast on an integral constant. More...
 
template<typename Type , Type... Values>
using fcppt::brigand::list_c = ::brigand::list< std::integral_constant< Type, Values >... >
 A list of integral_constants. More...
 
template<typename Sequence >
using fcppt::brigand::max_value = ::brigand::fold< Sequence, ::brigand::front< Sequence >, ::brigand::if_< ::brigand::bind< ::brigand::greater, ::brigand::_state, ::brigand::_element >, ::brigand::_state, ::brigand::_element > >
 Calculates the maximum value in a sequence. More...
 
template<typename Type >
using fcppt::brigand::numeric_max = std::integral_constant< Type, std::numeric_limits< Type >::max() >
 Metafunction to compute the maximum value of a type. More...
 
template<typename Pair >
using fcppt::brigand::pair_first = typename Pair::first_type
 The first type of a pair. More...
 
template<typename Pair >
using fcppt::brigand::pair_second = typename Pair::second_type
 The second type of a pair. More...
 
template<typename Sequence , typename IntType = int>
using fcppt::brigand::partial_sums = ::brigand::fold< Sequence, fcppt::brigand::list_c< IntType, 0 >, ::brigand::bind< ::brigand::push_back, ::brigand::_state, ::brigand::bind< ::brigand::plus, ::brigand::bind< ::brigand::back, ::brigand::_state >, ::brigand::_element > > >
 Calculates a new sequence that consists of the sums of the old sequence. More...
 
template<typename Set1 , typename Set2 >
using fcppt::brigand::set_difference = ::brigand::fold< Set1, ::brigand::set<>, ::brigand::if_< ::brigand::bind< ::brigand::has_key, ::brigand::pin< Set2 >, ::brigand::_element >, ::brigand::_state, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element > > >
 The difference of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::brigand::set_intersection = ::brigand::fold< Set1, ::brigand::set<>, ::brigand::if_< ::brigand::bind< ::brigand::has_key, ::brigand::pin< Set2 >, ::brigand::_element >, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element >, ::brigand::_state > >
 The intersection of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::brigand::set_symmetric_difference = fcppt::brigand::set_union< fcppt::brigand::set_difference< Set1, Set2 >, fcppt::brigand::set_difference< Set2, Set1 > >
 The symmetric difference of two sets. More...
 
template<typename Set1 , typename Set2 >
using fcppt::brigand::set_union = ::brigand::fold< Set1, Set2, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element > >
 The union of two sets. More...
 

Functions

template<typename Sequence , typename Function >
void fcppt::brigand::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::brigand::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::brigand::print (fcppt::io::ostream &_stream)
 Pretty prints a brigand sequence. More...
 
template<typename MaxIndex , typename Index , typename Function , typename FailFunction >
decltype(auto) fcppt::brigand::runtime_index (Index const _index, Function const &_function, FailFunction const &_fail_function)
 Transforms a runtime index into a an integral constant. More...
 
template<typename Sequence >
fcppt::string fcppt::brigand::sequence_to_string ()
 Converts a sequence to a string. More...
 

Typedef Documentation

◆ all_of

template<typename Sequence , typename Predicate >
using fcppt::brigand::all_of = typedef typename fcppt::brigand::detail::all_of_impl< Sequence, Predicate >::type

Checks if a predicate is true for every element.

Template Parameters
SequenceMust be a brigand sequence.
PredicateA unary predicate.

◆ ceil_div

template<typename Type , Type Dividend, Type Divisor>
using fcppt::brigand::ceil_div = typedef typename fcppt::brigand::detail::ceil_div< Type, Dividend, Divisor >::type

Calculates a division of integral contants rounded towards infinity.

Calculates Dividend / Divisor rounded towards infinity. For exabrigande, 5 / 3 would result in 2.

typedef
unsigned,
10u,
3u
>
static_assert(
std::is_same<
std::integral_constant<
unsigned,
4u
>
>::value,
""
);
Template Parameters
TypeMust be an unsigned integral type
DividendThe dividend
DivisorThe divisor

◆ equal_to

template<typename Sequence1 , typename Sequence2 >
using fcppt::brigand::equal_to = typedef ::brigand::all< ::brigand::transform< Sequence1, Sequence2, ::brigand::bind< ::brigand::apply, ::brigand::bind< ::brigand::equal_to, ::brigand::_1, ::brigand::_2 > > >, ::brigand::identity< ::brigand::_1 > >

Checks if two sequences of integral constants are equal.

Checks if Sequence1 is equal to Sequence2. Both sequences must be a of the same length.

Template Parameters
Sequence1A brigand sequence of integral constants.
Sequence2A brigand sequence of integral constants.

◆ flip_map

template<typename Map >
using fcppt::brigand::flip_map = typedef ::brigand::transform< Map, ::brigand::bind< fcppt::brigand::flip_pair, ::brigand::_1 > >

Flips a brigand 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 brigand map.

◆ flip_pair

template<typename Pair >
using fcppt::brigand::flip_pair = typedef ::brigand::pair< fcppt::brigand::pair_second< Pair >, fcppt::brigand::pair_first< Pair > >

Flips a brigand pair.

Swaps first and second of Pair.

Template Parameters
PairMust be a brigand pair.

◆ found_t

template<typename Sequence , typename Type >
using fcppt::brigand::found_t = typedef ::brigand::found< Sequence, ::brigand::bind< std::is_same, ::brigand::pin< Type >, ::brigand::_1 > >

Checks if a sequence contains an element.

Checks if Sequence contains Type.

◆ implication

template<typename Left , typename Right >
using fcppt::brigand::implication = typedef ::brigand::or_< ::brigand::not_< Left >, Right >

The implication function: Left -> Right.

Calculates the implication of Left and Right. Equal to (not Left) or Right)

typedef
std::false_type,
std::true_type
>
static_assert(
std::true_type
>::value,
""
);
Template Parameters
LeftA boolean expression
RightA boolean expression

◆ integral_cast

template<typename IntegralType , typename Conv , typename Integral >
using fcppt::brigand::integral_cast = typedef std::integral_constant< IntegralType, fcppt::brigand::detail::integral_cast_value< IntegralType, Conv, Integral >::value >

Does an integral cast on an integral constant.

Casts Integral to an integral constant of type IntegralType. The cast is done using Conv from fcppt.casts.

typedef
std::integral_constant<
int,
2
> integral;
typedef
unsigned,
integral
>::type
static_assert(
std::is_same<
>,
unsigned
>::value
&&
result::value
==
2u,
""
);
Template Parameters
IntegralTypeAn integral type to cast to
ConvA cast function from fcppt.casts
IntegralAn integral constant to cast from

◆ list_c

template<typename Type , Type... Values>
using fcppt::brigand::list_c = typedef ::brigand::list< std::integral_constant< Type, Values >... >

A list of integral_constants.

◆ max_value

template<typename Sequence >
using fcppt::brigand::max_value = typedef ::brigand::fold< Sequence, ::brigand::front< Sequence >, ::brigand::if_< ::brigand::bind< ::brigand::greater, ::brigand::_state, ::brigand::_element >, ::brigand::_state, ::brigand::_element > >

Calculates the maximum value in a sequence.

Calculates the maximum value in Sequence.

// Calculate the maximum size of all the types
typedef
brigand::list<
short,
int,
long
>
types;
typedef
brigand::transform<
types,
brigand::sizeof_<
brigand::_1
>
>
>
static_assert(
brigand::sizeof_<
long
>
>::value,
""
);
Template Parameters
SequenceA non empty brigand sequence.

◆ numeric_max

template<typename Type >
using fcppt::brigand::numeric_max = typedef std::integral_constant< Type, std::numeric_limits< Type >::max() >

Metafunction to compute the maximum value of a type.

Template Parameters
TypeMust be a type such that std::numeric_limits<Type>::max() is defined.

◆ pair_first

template<typename Pair >
using fcppt::brigand::pair_first = typedef typename Pair::first_type

The first type of a pair.

Template Parameters
PairMust be a brigand::pair.

◆ pair_second

template<typename Pair >
using fcppt::brigand::pair_second = typedef typename Pair::second_type

The second type of a pair.

Template Parameters
PairMust be a brigand::pair.

◆ partial_sums

template<typename Sequence , typename IntType = int>
using fcppt::brigand::partial_sums = typedef ::brigand::fold< Sequence, fcppt::brigand::list_c< IntType, 0 >, ::brigand::bind< ::brigand::push_back, ::brigand::_state, ::brigand::bind< ::brigand::plus, ::brigand::bind< ::brigand::back, ::brigand::_state >, ::brigand::_element > > >

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

For the integral constantsn (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)

typedef
int,
3,
4,
5
>
vec;
typedef
vec
>
static_assert(
int,
0,
3,
7,
12
>
>::value,
""
);
Template Parameters
SequenceA brigand sequence of integral constant types.
IntTypeThe integer type to use for the first zero.

◆ set_difference

template<typename Set1 , typename Set2 >
using fcppt::brigand::set_difference = typedef ::brigand::fold< Set1, ::brigand::set<>, ::brigand::if_< ::brigand::bind< ::brigand::has_key, ::brigand::pin< Set2 >, ::brigand::_element >, ::brigand::_state, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element > > >

The difference of two sets.

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

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

◆ set_intersection

template<typename Set1 , typename Set2 >
using fcppt::brigand::set_intersection = typedef ::brigand::fold< Set1, ::brigand::set<>, ::brigand::if_< ::brigand::bind< ::brigand::has_key, ::brigand::pin< Set2 >, ::brigand::_element >, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element >, ::brigand::_state > >

The intersection of two sets.

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

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

◆ set_symmetric_difference

template<typename Set1 , typename Set2 >
using fcppt::brigand::set_symmetric_difference = typedef fcppt::brigand::set_union< fcppt::brigand::set_difference< Set1, Set2 >, fcppt::brigand::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 brigand set.
Set2Must be a brigand set.

◆ set_union

template<typename Set1 , typename Set2 >
using fcppt::brigand::set_union = typedef ::brigand::fold< Set1, Set2, ::brigand::bind< ::brigand::insert, ::brigand::_state, ::brigand::_element > >

The union of two sets.

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

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

Function Documentation

◆ for_each_break()

template<typename Sequence , typename Function >
void fcppt::brigand::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
SequenceA brigand sequence.
FunctionThe 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::brigand::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 cobrigandexities of this function are linear in the size of the BRIGAND 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/brigand/invoke_on.hpp>
#include <fcppt/cast/enum_to_underlying.hpp>
#include <fcppt/cast/to_unsigned.hpp>
#include <fcppt/variant/holds_type.hpp>
#include <fcppt/variant/object.hpp>
#include <fcppt/config/external_begin.hpp>
#include <brigand/sequences/list.hpp>
#include <cassert>
#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
typedef
brigand::list<
bgr,
rgb
>
static_color_types;
// The variant type that can hold any of the static color types
typedef
static_color_types
>
color_variant;
// Transforms a concrete color type into a color_variant. This function will be
// used with invoke_on.
struct create_function
{
typedef color_variant result_type;
template<
typename ConcreteColor
>
result_type
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
)
);
assert(
rgb
>(
variant
)
);
}
Template Parameters
SequenceA brigand sequence.
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::brigand::print ( fcppt::io::ostream _stream)

Pretty prints a brigand sequence.

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 brigand sequence.
Parameters
_streamThe stream to print to.
Returns
_stream

◆ runtime_index()

template<typename MaxIndex , typename Index , typename Function , typename FailFunction >
decltype( auto ) fcppt::brigand::runtime_index ( Index const  _index,
Function const &  _function,
FailFunction const &  _fail_function 
)
inline

Transforms a runtime index into a an integral constant.

Passes _index as an integral constant to _function if _index is less than MaxIndex::value, and returns its result. Otherwise, the result of _fail_function is returned.

Template Parameters
IndexAn unsigned integer type.
MaxIndexAn integral constant with element type Index.
FunctionA function callable as R (std::integral_constant<Index,N>) for every N of type Index, where R is the result type.
FailFunctionA function callable as R(), where R is the result type.

◆ sequence_to_string()

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

Converts a sequence to a string.

Template Parameters
SequenceMust be a brigand sequence.