Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Metaprogramming with tuples-of-types and the std::tuple
record.
The metaprogramming part of this header complements typelist.hpp and allows some additional manipulations on type sequences, especially to integrate with the Tuples provided by the standard library.
Definition in file tuple-helper.hpp.
#include "lib/meta/typelist.hpp"
#include "lib/meta/typelist-util.hpp"
#include "lib/meta/typeseq-util.hpp"
#include "lib/meta/variadic-helper.hpp"
#include "lib/meta/util.hpp"
#include <tuple>
#include <utility>
Typedefs | |
template<class TUP > | |
using | disable_if_Tuple = lib::meta::disable_if< lib::meta::is_Tuple< std::remove_reference_t< TUP > >> |
template<class TUP > | |
using | enable_if_Tuple = lib::meta::enable_if< lib::meta::is_Tuple< std::remove_reference_t< TUP > >> |
template<class SRC , class TAR , size_t i> | |
using | ExtractArg = typename ElementExtractor< SRC, TAR >::template Access< i > |
template<typename TYPES > | |
using | Tuple = typename BuildTupleType< TYPES >::Type |
Build a std::tuple from types given as type sequence. More... | |
Functions | |
template<typename TYPES , class SRC > | |
Tuple< TYPES > | buildTuple (SRC values) |
convenience shortcut to build a tuple from some suitable source data. More... | |
template<typename... TYPES> | |
std::string | dump (std::tuple< TYPES... > const &tuple) |
convenience function to dump a given tuple's contents. More... | |
template<class TUP , class FUN , typename = enable_if_Tuple<TUP>> | |
void | forEach (TUP &&tuple, FUN fun) |
Tuple iteration: perform some arbitrary operation on each element of a tuple. More... | |
template<class TUP , class FUN , typename = enable_if_Tuple<TUP>> | |
auto | mapEach (TUP &&tuple, FUN fun) |
Apply some arbitrary function onto all elements of a tuple. More... | |
template<typename TY > | |
std::string | toString (TY const &val) noexcept |
get some string representation of any object, reliably. More... | |
Namespaces | |
lib | |
Implementation namespace for support and library code. | |
using Tuple = typename BuildTupleType<TYPES>::Type |
Build a std::tuple
from types given as type sequence.
Types
to mark a type sequence of types as such. This allows to pass such a sequence as first-class citizen. The standard library often (ab)uses the std::tuple for this purpose, which is an understandable, yet inferior design choice. We should always favour dedicated types over clever re-use of existing types. Definition at line 186 of file tuple-helper.hpp.
struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Node< H, TAIL > > |
Class Members | ||
---|---|---|
typedef typename Types< Node < H, TAIL > >::Seq |
Seq | |
typedef typename BuildTupleType< Seq >::Type |
Type |
struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< NullType > |
Class Members | ||
---|---|---|
typedef typename BuildTupleType< Types <> >::Type |
Type |
struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Types< TYPES... > > |
Class Members | ||
---|---|---|
VariadicSeq | ||
typedef typename BuildTupleType< VariadicSeq > ::Type |
Type |
struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< TySeq< TYPES... > > |
|
inlinenoexcept |
get some string representation of any object, reliably.
A custom string conversion operator is invoked, if applicable, while all lexically convertible types (numbers etc) are treated by boost::lexical_cast. For double or float values, hard wired rounding to a fixed number of digits will be performed, to yield a predictable display of printed unit-test results.
StringConf<TY>
, yet this solution might be brittle. If you want pointers to be indicated (with address), consider using util::showPtr explicitly. Definition at line 191 of file format-obj.hpp.
References util::toString().
Referenced by FormatHelper_test::check2String(), and util::toString().
void lib::meta::forEach | ( | TUP && | tuple, |
FUN | fun | ||
) |
Tuple iteration: perform some arbitrary operation on each element of a tuple.
Definition at line 98 of file tuple-helper.hpp.
References lib::meta::forEach().
Referenced by lib::meta::forEach().
auto lib::meta::mapEach | ( | TUP && | tuple, |
FUN | fun | ||
) |
Apply some arbitrary function onto all elements of a tuple.
Definition at line 123 of file tuple-helper.hpp.
References lib::meta::mapEach().
Referenced by lib::meta::mapEach().
Tuple<TYPES> lib::meta::buildTuple | ( | SRC | values | ) |
convenience shortcut to build a tuple from some suitable source data.
For this to work, there needs to be a partial specialisation for (ElementExtractor) to deal with the concrete source type given.
Record<GenNode>
, which allows us to fill an (argument) tuple from a sequence of generic data values, with run-time type compatibility check. Definition at line 286 of file tuple-helper.hpp.
References lib::meta::buildTuple().
Referenced by lib::meta::buildTuple().
|
inline |
convenience function to dump a given tuple's contents.
Using the BuildTupleAccessor, we layer a stack of Instantiations of the TupleElementDisplayer temporarily on top of the given tuple, just to invoke a recursive call chain through these layers and get a string representation of each element in the tuple.
Definition at line 409 of file tuple-helper.hpp.
References lib::meta::dump().
Referenced by lib::meta::dump(), and LateBindInstance_test::verify_cornerCases().