iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages

Classes

struct  nrt::NotATypeError
 A type to indicate an error in metaprogramming. More...
 
class  nrt::Range< T >
 A generic range class. More...
 
struct  nrt::T2Type< T, val >
 Type-to-type class. More...
 
struct  nrt::nrt_traits< T, U >
 NRT type traits definition. More...
 
class  nrt::trivial_type
 A type trait class to specify whether a custom class is 'trivial,' e.g., can be malloc'd. More...
 
class  nrt::ValidValuesSpecList< T >
 Finite list valid values spec, everything listed at construction is valid, anything else is not. More...
 
class  nrt::ValidValuesSpecRange< T >
 Range-based valid values spec, bounds are included. More...
 
class  nrt::ValidValuesSpecRegex< T >
 Regex-based valid values spec, everything that is a match to the regex is considered valid. More...
 

Functions

template<typename Elem , typename Tupl , size_t i>
std::__add_ref< typename
std::enable_if< std::is_same
< Elem, typename
std::tuple_element< i, Tupl >
::type >::value, typename
std::__add_ref< Elem >::type >
::type >::type 
nrt::tget (Tupl &t)
 Add access to std::tuple elements by type. More...
 
template<typename Elem , typename Tupl , size_t i>
std::__add_c_ref< typename
std::enable_if< std::is_same
< Elem, typename
std::tuple_element< i, Tupl >
::type >::value, typename
std::__add_c_ref< Elem >::type >
::type >::type 
nrt::tget (Tupl const &t)
 Const version of nrt::tget() More...
 

Function Documentation

template<typename Elem , typename Tupl , size_t i>
std::__add_ref< typename std::enable_if< std::is_same< Elem, typename std::tuple_element< i, Tupl >::type >::value, typename std::__add_ref< Elem >::type >::type >::type nrt::tget ( Tupl &  t)
inline

Add access to std::tuple elements by type.

This allows one to access an element of an std::tuple by element type, rather than by element index as already provides by get<index>(tuple). Beware that we scan the tuple by increasing index starting at zero, so if you have two or more elements in your tuple that have the same type, the first one will be returned. Thus you should ensure that all elements in your tuple have a unique type. Example use is as follows:

std::tuple<int, float, double> tup(1, 2.0F, 3.0);
std::cout << nrt::tget<double>(tup) << std::endl; // displays 3

Here is an example of how to contain a tuple with two Point3D elements and access them by type. First we need to wrap each one and create a new type. Once forwarding constructors are supported in GCC this will be easier. Then we can access the elements by type (even though in the end they both derive from Point3D):

struct position : public nrt::Point3D<double>
{
position() : nrt::Point3D<double>() { }
position(nrt::Point3D<double> const & old) : nrt::Point3D<double>(old) { }
};
struct velocity : public nrt::Point3D<double>
{
velocity() : nrt::Point3D<double>() { }
velocity(nrt::Point3D<double> const & old) : nrt::Point3D<double>(old) { }
};
std::tuple<position, velocity> state;
std::get<0>(state) = nrt::Point3D<double>(1.0, 2.0, 3.0); // conventional tuple get()
std::get<1>(state) = nrt::Point3D<double>(4.0, 5.0, 6.0);
std::cout << "Position: " << nrt::tget<position>(state) << std::endl; // by-type nrt::tget()
std::cout << "Velocity: " << nrt::tget<velocity>(state) << std::endl;

Definition at line 50 of file TupleImpl.H.

template<typename Elem , typename Tupl , size_t i>
std::__add_c_ref< typename std::enable_if< std::is_same< Elem, typename std::tuple_element< i, Tupl >::type >::value, typename std::__add_c_ref< Elem >::type >::type >::type nrt::tget ( Tupl const &  t)
inline

Const version of nrt::tget()

Definition at line 70 of file TupleImpl.H.