
2011/1/25 Joachim Faulhaber <afojgo@googlemail.com>:
2011/1/25 Kraus Philipp <philipp.kraus@flashpixx.de>:
Hello,
I have written a template class and I would like tot "assert the type". My class should only use floating point types like double or float. Can I do this check with BOOST_STATIC_ASSERT or anything else? The class need not to
E.g. #include <boost/static_assert.hpp> #include <boost/type_traits/is_floating_point.hpp>
template<class Type> class real_holder { public: real_holder(Type val): _value(val) { BOOST_STATIC_ASSERT((is_floating_point<Type>::value)); } private: Type _value; };
... { real_holder<double> rh_d(1.0); //OK. real_holder<int> rh_i(1); // compiletime error: //boost::STATIC_ASSERTION_FAILURE<x> }
use a "countable type" (math: in N).
may be you need a different trait depending on the exact specification of your type.
You could use #include <boost/detail/is_incrementable.hpp> ... boost::detail::is_incrementable<Type> for countability, but this also includes pointers, iterators and other incrementable types. If you need to be more precise you can combine those traits using boost::mpl. HTH Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de