Date: 1999-11-29 17:06:30
I have a header file in my library that I use for determining "type traits".
I've taken the approach of a separate struct for each trait, instead of one
type_traits struct. Also note that these are under construction; for
example, is_pointer and is_reference are not specialized for cv-qualified
pointed to/referred types. I also would like to apologize for the
structures here that are not related to type traits; this header has become
something of a catch-all header. . . :) I just thought you might like a
place to start.
Below are predicates on types; each of these structs has a static const bool
member named "value", containing the result of the predicate.
-is_builtin_integer - true for short, int, long, char, wchar_t, bool (signed
-is_builtin_float - true for float, double, long double
-is_builtin_arithmetic - builtin_integer || builtin_float
-is_pointer - true for "T *"
-is_builtin_scalar - builtin_arithmetic || pointer
-is_integer - true iff std::numeric_limits<T>::is_integer
-is_float - true iff std::numeric_limits<T>::is_specialized && !integer
-is_arithmetic - integer || float
-is_scalar - arithmetic || pointer
-is_empty - true for empty types (doesn't work)
-is_reference - true for "T &"
This next predicate is a binary predicate. Other than taking two template
parameters, it is exactly like the unary predicates above.
-is_same_type - true if "T" and "R" are the same type
The next two structs are not predicates; they are type operations. They
have a single typedef named "type", which is the result of the type
-remove_reference - Returns T unless T is a reference type U &, in which
case it returns U
-add_reference - Returns T & unless T is a reference type U &, in which case
it returns T
Also included is the original "constructor_parameter" which started this
whole thing; BTW, I hate the name -- it was always just a placeholder that I
haven't had time to replace; my original intention was to see how I could
make it more generic and then choose a suitable name.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk