Answer to
@James is clearly right, but you can still have some problems, however, if the user does not provide the correct typedefs.
It can be argued that the types used are correct using compile-time verification tools. Depending on the version of C ++ you are using, you may need to use Boost.
In C ++ 0x, this is done by combining:
static_assert : a new compile time checker that allows you to specify a message- a
type_traits header that provides some predicates like std::is_integral or std::is_floating_point
Example:
template <typename TDerived> struct Base { typedef typename BaseTraits<TDerived>::IntType IntType; typedef typename BaseTraits<TDerived>::FloatType FloatType; static_assert(std::is_integral<IntType>::value, "BaseTraits<TDerived>::IntType should have been an integral type"); static_assert(std::is_floating_point<FloatType>::value, "BaseTraits<TDerived>::FloatType should have been a floating point type"); };
This is very similar to the typical idioms of Defensive Programming in the run-time world.
Matthieu M.
source share