OSVR-Core
Classes | Typedefs | Functions
osvr::typepack Namespace Reference

A simple argument-pack-based metaprogramming library, inspired by and based partially on https://ericniebler.github.io/meta. More...

Classes

struct  always
 A Alias Class that always returns T. More...
 
struct  compose
 Compose the Alias Classes Fs in the parameter pack Ts. More...
 
struct  compose< F0 >
 
struct  compose< F0, Fs... >
 
struct  defer
 A wrapper that defers the instantiation of a template C with type parameters Ts in a lambda or let expression. More...
 
struct  list
 A wrapper for a template parameter pack of types. More...
 
struct  list< list< Ts... > >
 
struct  quote
 Turn a class template or alias template C into a Alias Class. More...
 
class  TypeKeyedBase
 CRTP base for type-keyed data types, providing a unified interface (compile-time polymorphism) and shared functionality. More...
 
class  TypeKeyedMap
 A class that uses types as an index into a container with uniform-typed contents, somewhat like a map except all elements are default-constructed rather than having an optional "not set" status. More...
 
class  TypeKeyedTuple
 Provides a data structure where a value of heterogeneous data types may be stored at runtime for each of the "key" types in a list. More...
 

Typedefs

template<typename... Bools>
using and_ = t_< detail::and_impl< Bools... >>
 Logically and together all the integral constant-wrapped Boolean parameters, with short-circuiting. More...
 
template<typename F , typename... Args>
using apply = typename F::template apply< Args... >
 Apply an alias class.
 
template<typename F , typename Args >
using apply_list = apply< detail::apply_list_< F, Args >>
 Apply an alias class, exploding the list of args.
 
template<bool V>
using bool_ = std::integral_constant< bool, V >
 Alias template to simplify creating a boolean integral constant.
 
template<typename... Ts>
using coerce_list = t_< list< Ts... >>
 Will turn whatever is passed into it into the simplest list.
 
template<typename... Lists>
using concat = t_< detail::concat_< Lists... >>
 Concatenates several lists into a single list. More...
 
template<typename Haystack , typename Needle >
using contains = apply_list< quote< or_ >, transform< Haystack, detail::is_< Needle >>>
 Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_type or std::false_type. More...
 
template<typename List , typename Needle >
using find_first = t_< detail::find_first_impl< Needle, 0, List >>
 Returns the zero-based index of the first instance of Needle in List. More...
 
template<typename List , typename State , typename Fun >
using fold = t_< detail::fold_< List, State, Fun >>
 Fold the list (right) with the given alias class and initial state. More...
 
template<typename T >
using has_type = t_< detail::has_type_< T >>
 An alias for std::true_type if T::type exists and names a type; otherwise, it's an alias for std::false_type. More...
 
template<typename... Args>
using if_ = t_< detail::if_impl< Args... >>
 Select one type or another depending on a compile-time Boolean integral constant type. More...
 
template<bool If, typename... Args>
using if_c = t_< detail::if_impl< bool_< If >, Args... >>
 Select one type or another depending on a compile-time Boolean value.
 
template<typename Bool >
using not_ = bool_<!Bool::value >
 Logical not on a single boolean.
 
template<typename... Bools>
using or_ = t_< detail::or_impl< Bools... >>
 Logically or together all the integral constant-wrapped Boolean parameters, with short-circuiting. More...
 
template<typename List , typename T >
using push_back = apply_list< detail::push_back_impl< T >, List >
 
template<typename List , typename T >
using push_front = apply_list< detail::push_front_impl< T >, List >
 
template<template< typename... > class C>
using quote_trait = compose< quote< t_ >, quote< C >>
 Turn a trait C into a Alias Class.
 
template<typename... Ts>
using size = detail::size< coerce_list< Ts... >>
 Get the size of a list (number of elements.)
 
template<typename... Ts>
using length = size< coerce_list< Ts... >>
 Synonym for typepack::size.
 
template<std::size_t V>
using size_t_ = std::integral_constant< std::size_t, V >
 Alias template to simplify creating an integral constant of size_t.
 
template<typename... List>
using head = typename detail::split_list_< List... >::head
 Get the first element of a list.
 
template<typename... List>
using tail = typename detail::split_list_< List... >::tail
 Get the list without its first element.
 
template<typename T >
using t_ = typename T::type
 A convenience alias template to extract the nested type within the supplied T. More...
 
template<typename List , typename Fun >
using transform = t_< detail::transform_< List, Fun >>
 Given a list and an alias class, apply the alias class to each element in the list and return the results in a list. More...
 
template<typename... Ts>
using void_ = apply< always< void >, Ts... >
 An alias for void.
 

Functions

template<typename List , typename F , typename... Args>
void for_each_type (F &&f, Args &&... args)
 Run-time operation on a type list: given a function object, a type list, and optional arguments to be forwarded to the function call, construct each type in the type list in turn and call the function-call-operator of your functor with it (and your optional additional arguments). More...
 

Detailed Description

A simple argument-pack-based metaprogramming library, inspired by and based partially on https://ericniebler.github.io/meta.

It includes an as-needed subset of the features of meta, modified as needed to build on MSVC 2013, as well as additional functionality not found in meta.

Typedef Documentation

§ and_

template<typename... Bools>
using osvr::typepack::and_ = typedef t_<detail::and_impl<Bools...>>

Logically and together all the integral constant-wrapped Boolean parameters, with short-circuiting.

§ concat

template<typename... Lists>
using osvr::typepack::concat = typedef t_<detail::concat_<Lists...>>

Concatenates several lists into a single list.

Precondition
The parameters must all be instantiations of typepack::list.
Complexity
\( O(L) \) where \( L \) is the number of lists in the list of lists.

§ contains

template<typename Haystack , typename Needle >
using osvr::typepack::contains = typedef apply_list<quote<or_>, transform<Haystack, detail::is_<Needle>>>

Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_type or std::false_type.

§ find_first

template<typename List , typename Needle >
using osvr::typepack::find_first = typedef t_<detail::find_first_impl<Needle, 0, List>>

Returns the zero-based index of the first instance of Needle in List.

Will fail to compile if not found.

§ fold

template<typename List , typename State , typename Fun >
using osvr::typepack::fold = typedef t_<detail::fold_<List, State, Fun>>

Fold the list (right) with the given alias class and initial state.

§ has_type

template<typename T >
using osvr::typepack::has_type = typedef t_<detail::has_type_<T>>

An alias for std::true_type if T::type exists and names a type; otherwise, it's an alias for std::false_type.

§ if_

template<typename... Args>
using osvr::typepack::if_ = typedef t_<detail::if_impl<Args...>>

Select one type or another depending on a compile-time Boolean integral constant type.

§ or_

template<typename... Bools>
using osvr::typepack::or_ = typedef t_<detail::or_impl<Bools...>>

Logically or together all the integral constant-wrapped Boolean parameters, with short-circuiting.

§ t_

template<typename T >
using osvr::typepack::t_ = typedef typename T::type

A convenience alias template to extract the nested type within the supplied T.

The name was chosen to parallel how the traits in C++14 (like std::enable_if) have been complemented by aliases ending in _t (like std::enable_if_t<COND> being equivalent to typename std::enable_if<COND>::type)

Note that the name is t_, unlike in meta where the semi-illegal name _t is used. (Leading underscores are between risky and not permitted.)

§ transform

template<typename List , typename Fun >
using osvr::typepack::transform = typedef t_<detail::transform_<List, Fun>>

Given a list and an alias class, apply the alias class to each element in the list and return the results in a list.

Function Documentation

§ for_each_type()

template<typename List , typename F , typename... Args>
void osvr::typepack::for_each_type ( F &&  f,
Args &&...  args 
)
inline

Run-time operation on a type list: given a function object, a type list, and optional arguments to be forwarded to the function call, construct each type in the type list in turn and call the function-call-operator of your functor with it (and your optional additional arguments).