FX::Generic::Traits< type > Class Template Reference
[Generic Tools in TnFOX]
#include <FXGenericTools.h>
Inherits FX::Generic::TraitsBasic< type >.
List of all members.
Detailed Description
template<typename type>
class FX::Generic::Traits< type >
Determines qualities of a type via introspection.
This is an amazingly useful class. It is divided into two parts, FX::Generic::TraitsBasic and FX::Generic::Traits with the basic base class providing all the commonly used (and least compiler demanding) traits. If you can, use TraitsBasic where possible.
You may also find FX::Generic::FnInfo useful for working with function pointers when isFunctionPtr is true. Traits provided by TraitsBasic:
- isVoid, if true then all rest below are irrelevent
- isPtr, true when type is a pointer. False if reference to a pointer.
- isRef, true when type is a reference
- isPtrToCode, true when type points to code
- isMemberPtr, true when type is a member function pointer
- isFunctionPtr, true when type is a function pointer
- isValue, true when type is a value (therefore neither of the above)
- isIndirect, true when type is an indirection to real data (the previous is false)
- isConst, true when type is const
- isVolatile, true when type is volatile
- isArray, true when the base type is an array
- isFloat, true when base type is a floating point value
- isInt, true when base type is an integer
- isSigned, true when base type is signed
- isUnsigned, true when base type is unsigned
- isArithmetical, true when base type can be used to do maths
- isIntegral or isBasic, true when base type is one of the basic or integral types
- holdsData, true when the previous is false and is not a function pointer. True for enums even though they are equivalent to an int. True for arrays.
- isPOD, true when the base type is Plain Old Data (POD) and therefore can be memcpyed or memcmped. See notes below.
Furthermore, the following types are defined:
- baseType: This is the type less any indirection.
- asConstParam: This is the type plus const, but only where that makes sense ie; integral types remain non-const
- asRWParam: This is the best type for passing this type as a parameter.
- asROParam: Same as asRWParam but const where it makes sense ie; values remain as-is, pointers become const pointers and other types (structs, classes, enums etc.) become const references.
More advanced traits not provided by TraitsBasic (note that these require more compiler time and require fully known types ie; not just predeclarations):
- isEnum, true when base type is an enum (note: depends on an implicit conversion to
int
being available, which may be provided by a class operator. May give false positives if sizeof(type)==sizeof
(enum) and provides operator int()
)
- isPolymorphic, true when the base type contains virtual members (note: depends on the compiler saying a class with a virtual member is bigger)
What is the best type for passing as a parameter? Well basic types like int and pointers should be passed as-is along with enums whereas structures, classes, arrays etc. should be passed by reference for efficiency. asROParam only applies const when the parameter type permits altering of external data (except for enums, just in case isEnum is misdiagnosed). Convertibility is always maintained (ie; so the compiler can always convert your type to asRWParam or asROParam) so this is ideal for compile-time parameter specification.
Notes:
isPOD currently only becomes true if isBasic is true as there is no way currently in the ISO C++ standard to determine if a class is POD. You can manually specify PODness using FX::Generic::ClassTraits.
|
Public Types |
typedef leastIndir< type >::value | baseType |
typedef select< isIntegral||isIndirect,
type, typename addRef< type >
::value >::value | asRWParam |
typedef addConstI<!isIntegral
&&!isRef, type >::value | asConstParam |
typedef TL::at< ROParams,((isValue
&&isBasic)||isRef)?0:(isIndirect)?1:2 >
::value | asROParam |
Static Public Attributes |
static const bool | isEnum |
static const bool | isPolymorphic |
static const bool | isVoid |
static const bool | isPtr |
static const bool | isRef |
static const bool | isPtrToCode |
static const bool | isMemberPtr |
static const bool | isFunctionPtr |
static const bool | isValue |
static const bool | isIndirect |
static const bool | isConst |
static const bool | isVolatile |
static const bool | isArray |
static const bool | isFloat |
static const bool | isInt |
static const bool | isSigned |
static const bool | isUnsigned |
static const bool | isArithmetical |
static const bool | isIntegral |
static const bool | isBasic |
static const bool | holdsData |
static const bool | isPOD |
Protected Types |
typedef FnInfo< type > | fnInfo |
The documentation for this class was generated from the following file: