Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
tuple-helper.hpp File Reference

Metaprogramming with tuples-of-types and the std::tuple record. More...

Go to the source code of this file.

Description

Metaprogramming with tuples-of-types and the std::tuple record.

This header complements typelist.hpp and provides a bridge from type sequences to the tuple type provided by the standard library, including traits and helpers to build tuple types from metaprogramming and to pretty-print tuples.

Notably, a concept tuple_like is provided, which is satisfied for any type in compliance with the »tuple protocol«. Together with a [generic accessor][lib::meta::getElm], this allows to handle all tuple-like types uniformly.

Note
Due to an unfortunate limitation of the standard, we're forced to provide our own alternative implementation to replace std::apply, so that a function can be applied to any tuple-like

Furthermore, a generic iteration construct is provided, to instantiate a generic Lambda for each element of a given tuple, which allows to write generic code »for each tuple element«.

See also
control::CommandDef usage example
TupleHelper_test
typelist.hpp
function.hpp
generator.hpp

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>
#include <functional>

Namespaces

namespace  util
 
namespace  lib
 Implementation namespace for support and library code.
 
namespace  lib::meta
 
namespace  lib::meta::anonymous_namespace{tuple-helper.hpp}
 

Concepts

concept  lib::meta::tuple_sized
 
concept  lib::meta::tuple_adl_accessible
 
concept  lib::meta::tuple_mem_accessible
 
concept  lib::meta::tuple_element_accessible
 
concept  lib::meta::tuple_accessible
 
concept  lib::meta::tuple_like
 Concept to mark any type compliant to the »tuple protocol«
 

Typedefs

template<typename TYPES >
using Tuple = BuildTupleType< TYPES >::Type
 Build a std::tuple from types given as type sequence.
 
template<class SRC , class TAR , size_t i>
using ExtractArg = ElementExtractor< SRC, TAR >::template Access< i >
 

Classes

struct  is_Tuple< T >
 trait to detect tuple types More...
 
struct  is_Tuple< std::tuple< TYPES... > >
 
struct  is_Tuple< const std::tuple< TYPES... > >
 
struct  _InvokeMetafunTup< META, FUN, TUP >
 
struct  _InvokeMetafunTup< META, FUN, TUP & >
 
struct  ElmTypes< TUP >
 Specialisation of variadic access for any tuple-like. More...
 
struct  ElmTypes< TUP >::Extract< std::index_sequence< idx... > >
 
struct  BuildTupleType< SEQ >
 
struct  BuildTupleType< Types< TYPES... > >
 
struct  BuildTupleType< Node< H, TAIL > >
 
struct  BuildTupleType< Nil >
 
struct  RebindTupleTypes< TYPES >
 match and rebind the type sequence from a tuple More...
 
struct  RebindTupleTypes< std::tuple< TYPES... > >
 
struct  TupleConstructor< TYPES, _ElmMapper_ >
 Extensible Adapter to construct a distinct tuple from some arbitrary source type. More...
 
class  BuildTupleAccessor< _X_, TYPES, TUP, i >
 Decorating a tuple type with auxiliary data access operations. More...
 
class  BuildTupleAccessor< _X_, Types<>, TUP, i >
 
struct  TupleElementDisplayer< TY, BASE, TUP, idx >
 Helper to dump tuple contents. More...
 
struct  TupleElementDisplayer< Nil, TUP, TUP, n >
 
struct  StringConv< std::tuple< TYPES... > >
 

Functions

template<typename TY >
std::string toString (TY const &val) noexcept
 get some string representation of any object, reliably.
 
template<std::size_t idx, class TUP >
requires (tuple_like<std::remove_reference_t<TUP>>)
decltype(autogetElm (TUP &&tup)
 Helper for abstracted / unified access to member elements of any tuple-like
 
template<typename FUN , typename TUP , size_t... Idx>
constexpr decltype(auto__unpack_and_apply (FUN &&f, TUP &&tup, std::index_sequence< Idx... >)
 
template<class FUN , class TUP >
requires (tuple_like<remove_reference_t<TUP>>)
constexpr decltype(autoapply (FUN &&f, TUP &&tup) noexcept(can_nothrow_invoke_tup< FUN, TUP >)
 Replacement for std::apply — yet applicable to tuple-like custom types.
 
template<class TUP , class FUN >
requires (tuple_like<remove_reference_t<TUP>>)
constexpr void forEach (TUP &&tuple, FUN fun)
 Tuple iteration: perform some arbitrary operation on each element of a tuple.
 
template<class TUP , class FUN >
requires (tuple_like<remove_reference_t<TUP>>)
constexpr auto mapEach (TUP &&tuple, FUN fun)
 Apply some arbitrary function onto all elements of a tuple.
 
template<typename TYPES , class SRC >
Tuple< TYPESbuildTuple (SRC &&values)
 convenience shortcut to build a tuple from some suitable source data.
 
template<typename... TYPES>
std::string dump (std::tuple< TYPES... > const &tuple)
 convenience function to dump a given tuple's contents.
 

Variables

template<class FUN , class TUP >
constexpr bool can_nothrow_invoke_tup = _InvokeMetafunTup<std::is_nothrow_invocable,FUN,TUP>::Type::value
 

Class Documentation

◆ lib::meta::anonymous_namespace{tuple-helper.hpp}::_InvokeMetafunTup

struct lib::meta::anonymous_namespace{tuple-helper.hpp}::_InvokeMetafunTup
Class Members
typedef decay_t< TUP > Tupl
typedef Seq Elms
typedef Seq Args
typedef Type Type
+ Collaboration diagram for _InvokeMetafunTup< META, FUN, TUP >:

◆ lib::meta::anonymous_namespace{tuple-helper.hpp}::_InvokeMetafunTup< META, FUN, TUP & >

struct lib::meta::anonymous_namespace{tuple-helper.hpp}::_InvokeMetafunTup< META, FUN, TUP & >
Class Members
typedef decay_t< TUP > Tupl
typedef typename template Apply< add_lvalue_reference_t > Elms
typedef Seq Args
typedef Type Type
+ Collaboration diagram for _InvokeMetafunTup< META, FUN, TUP & >:

◆ lib::meta::ElmTypes< TUP >::Extract< std::index_sequence< idx... > >

struct lib::meta::ElmTypes< TUP >::Extract< std::index_sequence< idx... > >
Class Members
typedef Types< tuple_element_t< idx, TUP > ... > ElmTypes
+ Collaboration diagram for ElmTypes< TUP >::Extract< std::index_sequence< idx... > >:

◆ lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Types< TYPES... > >

struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Types< TYPES... > >
Class Members
typedef tuple< TYPES... > Type
+ Collaboration diagram for BuildTupleType< Types< TYPES... > >:

◆ lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Node< H, TAIL > >

struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Node< H, TAIL > >
Class Members
typedef Types< Node< H, TAIL > >::Seq Seq
typedef Type Type
+ Collaboration diagram for BuildTupleType< Node< H, TAIL > >:

◆ lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Nil >

struct lib::meta::anonymous_namespace{tuple-helper.hpp}::BuildTupleType< Nil >
Class Members
typedef tuple<> Type
+ Collaboration diagram for BuildTupleType< Nil >:

◆ lib::meta::RebindTupleTypes

struct lib::meta::RebindTupleTypes
Class Members
typedef Seq Seq
typedef List List
+ Collaboration diagram for RebindTupleTypes< TYPES >:

◆ lib::meta::RebindTupleTypes< std::tuple< TYPES... > >

struct lib::meta::RebindTupleTypes< std::tuple< TYPES... > >
Class Members
typedef Seq Seq
typedef List List
+ Collaboration diagram for RebindTupleTypes< std::tuple< TYPES... > >:

◆ lib::meta::BuildTupleAccessor< _X_, Types<>, TUP, i >

class lib::meta::BuildTupleAccessor< _X_, Types<>, TUP, i >
Class Members
typedef _X_< Nil, TUP, TUP, i > Product
+ Collaboration diagram for BuildTupleAccessor< _X_, Types<>, TUP, i >: