library of assembled shared sources |
http://lass.cocamware.com |
#include <type_traits.h>
Data Structures | |
struct | ConstTraits |
struct | ConstTraits< const U & > |
struct | ConstTraits< const U > |
struct | ConstTraits< U & > |
struct | PointerTraits |
struct | PointerTraits< U & > |
struct | PointerTraits< U * > |
struct | PointerTraits< U *& > |
struct | ReferenceTraits |
struct | ReferenceTraits< U & > |
Public Types | |
enum | { isConst = ConstTraits<T>::isConst } |
is true if referred type of T is constant. More... | |
enum | { isPointer = PointerTraits<TNonConst>::isPointer } |
is true if referred type of T is a pointer More... | |
enum | { isReference = ReferenceTraits<T>::isReference } |
is true if T is a reference More... | |
typedef T | Type |
type of T itself | |
typedef ConstTraits< T >::TNonConst | TNonConst |
strips const qualifier of refered type of T (but keeps reference if any). | |
typedef ConstTraits< T >::TConst | TConst |
add const qualifier to referred type of T (but keeps reference if any). | |
typedef PointerTraits < TNonConst >::TPointee | TPointee |
is type pointed to by referred type of T, NullType if not applyable. | |
typedef ReferenceTraits< T > ::TReferred | TReferred |
is type T refers to if T is a reference, is T otherwise | |
typedef ReferenceTraits< T > ::TReference | TReference |
is a reference to T if T is not a reference, is T otherwise | |
typedef ConstTraits< typename ReferenceTraits< T > ::TReferred >::TNonConst | TStorage |
strips const qualifier of refered type of T but without keeping reference if any. | |
Private Types | |
typedef ConstTraits< T >::TNonConst | TStripped |
In contrary to the type traits in boost[1] or loki[2], our TypeTraits tries to be smarter concerning reference. i.e. if T is a reference, TypeTraits will also report properties of the referred type. And if you request a related type, it will modify the referred type instead. All this should make sure you get exactly what you intend. (this is still to be proven in practice [BdG]).
Here's a list of the different fields (we suppose T is the template parameter):
true
if T is a constant type or a reference to a constant type, is false
otherwise. Notice that this will yield false
for non-const pointers to const types (const int*
) but true
for const pointers to non-const types (int* const
).const
qualifier of a type, e.g. const int
becomes int
but const int*
remains const int*
. For references, the const
qualifier is stripped of the referred type, e.g. const int&
becomes int&
.const
qualifier to the (reffered) type, const int*
becomes const int* const
, int&
becomes const int&
true
if T is a pointer or a reference to a pointer, is false
otherwise. Notice that int*&
will yield true.true
then TPointee is a typedef to the (referred) type points to, otherwise it will be equal to lass::meta::NullType. both int* const
and int*&
will yield int
, but int
and int&
will yield lass::meta::NullType.true
if T is a reference, is false
otherwise. both const int&
and int*&
are references, const int
and int*
are not.true
then strips the ampersand to get type T is refering to, otherwise it's T itself. both const int&
and const int
become const int
, int*&
and int*
become int*
.false
then adds the ampersand to get a type refering to a T, otherwise it's T itself. This solves the ill-formed reference-to-reference-to-type problem by keeping it a reference-to-type (what is exactly what you want). i.e. int
becomes int&
, but int&
remains int&
.const
qualifier of the referred type. e.g. if a const std::string&
is the type of a function parameter, you would like to store tempories as std::string
. This TStorage will give you this std::string
type.
T | isConst | TNonConst | TConst | isPointer | TPointee | isReference | TReferred | TReference | TStorage |
int | false | int | const int | false | NullType | false | int | int& | int |
int* | false | int* | int* const | true | int | false | int* | int*& | int* |
int* const | true | int* | int* const | true | int | false | int* const | int* const& | int* |
int& | false | int& | const int& | false | NullType | true | int | int& | int |
int*& | false | int*& | int* const& | true | int | true | int* | int*& | int* |
int* const& | true | int*& | int* const& | true | int | true | int* const | int* const& | int* |
const int | true | int | const int | false | NullType | false | const int | const int& | int |
const int* | false | const int* | const int* const | true | const int | false | const int* | const int*& | const int* |
const int* const | true | const int* | const int* const | true | const int | false | const int* const | const int* const& | const int* |
const int& | true | int& | const int& | false | NullType | true | const int | const int& | int |
const int*& | false | const int*& | const int* const& | true | const int | true | const int* | const int*& | const int* |
const int* const& | true | const int*& | const int* const& | true | const int | true | const int* const | const int* const& | const int* |
TypeTraits<U>::TPointee
will be the same as TypeTraits<typename TypeTraits<U>::TReferred>TPointee
, no matter what the type of U
is. The same is valid for isConst
and isPointer
. TConst
and TNonConst
are a bit different, for these the ampersand will again be added if U
is a reference.
There's really only one way to solve this, and that's exhaustive full specialisation of all possible parameters T. This means we should specialise it for int
, const int
, const int*
, ... (for each base type int
, you have to specialise for the twelve cases as in the table above).
Of course, it is impossible for a library to do this, because we can never know all types that will ever be needed. Therefore we have a twofolded solution:
namespace foo { struct Bar {}; } LASS_META_BROKEN_TYPE_TRAITS_SPECIALISATION(foo::Bar)
this exhaustive full specialisation might lead to an overflow of the compiler's internal heap while building. You're warned!
Definition at line 206 of file type_traits.h.
typedef ConstTraits<T>::TNonConst lass::meta::TypeTraits< T >::TStripped [private] |
Definition at line 269 of file type_traits.h.
typedef T lass::meta::TypeTraits< T >::Type |
typedef ConstTraits<T>::TNonConst lass::meta::TypeTraits< T >::TNonConst |
strips const
qualifier of refered type of T (but keeps reference if any).
Definition at line 280 of file type_traits.h.
typedef ConstTraits<T>::TConst lass::meta::TypeTraits< T >::TConst |
add const
qualifier to referred type of T (but keeps reference if any).
Definition at line 282 of file type_traits.h.
typedef PointerTraits<TNonConst>::TPointee lass::meta::TypeTraits< T >::TPointee |
is type pointed to by referred type of T, NullType if not applyable.
Definition at line 287 of file type_traits.h.
typedef ReferenceTraits<T>::TReferred lass::meta::TypeTraits< T >::TReferred |
is type T refers to if T is a reference, is T otherwise
Definition at line 292 of file type_traits.h.
typedef ReferenceTraits<T>::TReference lass::meta::TypeTraits< T >::TReference |
is a reference to T if T is not a reference, is T otherwise
Definition at line 294 of file type_traits.h.
typedef ConstTraits<typename ReferenceTraits<T>::TReferred>::TNonConst lass::meta::TypeTraits< T >::TStorage |
strips const
qualifier of refered type of T but without keeping reference if any.
Definition at line 297 of file type_traits.h.
anonymous enum |
anonymous enum |
anonymous enum |
Generated on Mon Nov 10 14:22:10 2008 for Library of Assembled Shared Sources by 1.5.7.1 |