|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2007-12-20 23:38:34
look at static_warning.hpp
Robert Ramey
Remi Ricard wrote:
> Hi,
>
> I want to warn user about a possible miss use of a function.
>
> Now I'm only able to stop the compilation with the following code
>
> template <typename ValueType>
> class simVec3 {
> .........
> /// Unary multiply by scalar.
> /// @param rsh The scalar to multiply the vector with
> template<class T> simVec3<ValueType>& operator *= (const T& rhs)
> {
> // The function should not be use like this
> // simVec<int> vec(1, 1, 1);
> // a *= 0.3; // since what a will contain is [0, 0, 0]
> BOOST_MPL_ASSERT_NOT(( boost::mpl::and_< \
> boost::is_floating_point<T>, \
> boost::is_integral<ValueType> > ));
>
> ValueType s=static_cast<ValueType>(rhs);
> vec[0]*=s; vec[1]*=s; vec[2]*=s; return *this;
> }
>
> What I would want is something like
> #if A_meta_function_returning_1_if_int_double
> #pragma message("simVec::Possible type truncation")
> #endif
>
> instead of the BOOST_MPL_ASSERT_NOT
>
>
> I also tried something like:
>
> template <bool x> struct AA;
> template <> struct AA<true> { enum {value = 1 }; };
> template <> struct AA<false> { enum {value = 0}; };
>
> template <typename U, typename V>
> double
> myfct(U u, V v)
> {
> #if ( AA< boost::mpl::and_< boost::is_integral<U>, \
> boost::is_floating_point<V> > > ::value )
> #pragma message("****** Hellop *********")
> #endif
>
> return u + v;
> }
>
> But the compilation is complaining about an unmatched parenthesis
>
>
> Remi
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net