Traits is a useful template technique to simplfy the implementation of some
classes. however, I met some questions when I tried to understand and
implement it.
Following is an example of traits template with specializations (copied
from Nathan C. Myer's 1995 article):
template <class numT>
struct float_traits { };
struct float_traits<float{
typedef float float_type;
enum { max_exponent = FLT_MAX_EXP };
static inline float_type epsilon() { return FLT_EPSILON; }
...
};
struct float_traits<double{
typedef double float_type;
enum { max_exponent = DBL_MAX_EXP };
static inline float_type epsilon() { return DBL_EPSILON; }
...
};
Here are my questions,1) Are "float_traits" really a C++ class? I saw many
people call this as traits class. but I cannot find keyword "class" in the
definition.2) Is "static inline" keyword a requirement for member functions
within traits? what is the benefit of using static keyword here?any kind of
reply is appreciated.hong