iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::nrt_traits< T, U > Struct Template Reference

#include <nrt/Core/Typing/TypeTraits.H>

template<class T, class U = T>
struct nrt::nrt_traits< T, U >

NRT type traits definition.

The struct is a convenient entry point to a variety of nrt related type traits used in metaprogramming for compile time information about templated types.

nrt_traits takes 1 or two types as arguments. The first argument is considered the primary, and traits which indicate the existence of a type (eg nrt_traits<float>::is_pixel) refer to the first argument. A second argument can be used of one wants to check if operators, promotions, stronger_of are defined for the two types (eg check if you can promote a T=PixRGB and U=float).

Void types can be accepted are treated like any other type. The exception is for nrt_traits<>::promote_type, which will be typedef'ed to to the non-void type.

some example:

using nrt;
//returns true as its OK to add, subtract etc... PixRGb and pod-types
bool const t1 = nrt_traits<PixRGB<float>,int>::has_arithmetic;
bool const t2 = nrt_traits<float>::is_pixel; //returns false;
struct A { }:
bool const t3 = nrt_traits<float,A>::is_promotable; //returns false
//nrt_traits<float,A>::promote_type; //this will evaluate to a nrt::NotATypeError type

Note for users creating/modifying classes. The promotion mechansim relies on operator*. When the comilier is trying to find an operator* that works it will first try to match for the exact type, then for any implicit conversions before getting eaten up by our fail mechanism. So, if you don't indend two types to be promotable but have constructors for one type that takes as an argument the other, make sure you use the 'explicit' keyword so the compiler can't use the constructor to implicitly convert.

See test-Traits.C for some more examples.

Examples:
tests/test-Traits.C.

Definition at line 85 of file TypeTraits.H.

Classes

struct  pixel_traits
 
struct  promote
 

Public Types

typedef std::remove_cv
< typename
std::remove_reference< T >
::type >::type 
Tc
 
typedef std::remove_cv
< typename
std::remove_reference< U >
::type >::type 
Uc
 
typedef promote::type promote_type
 

Static Public Attributes

static const bool is_pixel = pixel_traits::is_pixel
 check to see if we are a pixel
 
static const bool is_image = std::is_base_of<ImageBase, Tc>::value
 check to see if we are an Image
 
static const bool is_arithmetic = std::is_arithmetic<Tc>::value
 check to see if we are an arithmetic type (eg. float, int)
 
static const bool is_promotable = nrt::is_promotable<Tc,Uc>::value
 Determine if we can promote with this type.
 
static const bool is_equality_comparable = nrt::is_equality_comparable<Tc,Uc>::value
 Test for equality operators. More...
 
static const bool is_comparable = nrt::is_comparable<Tc,Uc>::value
 can we use comparison operators ==,<,<=,>,>= ? Tests both Uc and Tc on the rhs and lhs of the operator
 
static const bool has_arithmetic = nrt::has_arithmetic<Tc,Uc>::value
 can we use arithmetic operators +,-,*,/ ? Tests both Uc and Tt on the rhs and lhs of the operator
 
static const bool has_assign_arithmetic = nrt::has_assign_arithmetic<Tc,Uc>::value
 can we use operators +=,-=,*=,/= ? Not symmetric, tests for Tc on lhs, Uc on the rhs only.
 

Member Typedef Documentation

template<class T, class U = T>
typedef promote::type nrt::nrt_traits< T, U >::promote_type

Convenience access to the promotion mechanism. Users can check with is_promotable to see if access to 'type' will produce a valid type. This will be NotATypeError if we can't promote.

Definition at line 135 of file TypeTraits.H.

Member Data Documentation

template<class T, class U = T>
const bool nrt::nrt_traits< T, U >::is_equality_comparable = nrt::is_equality_comparable<Tc,Uc>::value
static

Test for equality operators.

The following traits test wether you can use various operators with a type, or with another type. All operators are symmetric (eg, test for x == y and y == x) accept the has_assign_arithmetic trait.can we use == operator ? Returns true of Tc==Uc and Uc==Tc is defined

Definition at line 116 of file TypeTraits.H.


The documentation for this struct was generated from the following file: