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 use a "countable type" (math: in N). Thanks Phil
AMDG On 1/25/2011 8:47 AM, Kraus Philipp wrote:
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 use a "countable type" (math: in N).
Does boost::is_float in boost/type_traits/is_float.hpp work? In Christ, Steven Watanabe
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 use a "countable type" (math: in N).
BOOST_STATIC_ASSERT(!boost::is_integral<T>::value);
On 2011-01-25 18:02:33 +0100, Igor R said:
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 use a "countable type" (math: in N).
BOOST_STATIC_ASSERT(!boost::is_integral<T>::value);
Thanks at all, but I think that's the best solution with is_integral Phil
2011/1/25 Kraus Philipp
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
use a "countable type" (math: in N).
may be you need a different trait depending on the exact specification of your type. Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de
2011/1/25 Joachim Faulhaber
2011/1/25 Kraus Philipp
: 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
#include 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
participants (5)
-
Igor R
-
Joachim Faulhaber
-
Kraus Philipp
-
Philipp Kraus
-
Steven Watanabe