Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-31 00:11:23


I have some code which checks is_scalar<T> for various T. When T is a
floating type, eventually is_convertible<T, detail::int_convertible>::value
is evaluated, which causes a giant chain of warnings. In order to kill them
off, I've committed the following two patches. The first one is the one
that's strictly needed to solve my problem. The 2nd one fixes the cases
where is_convertible<T,U> is checked, and U is an integral type.

However, this really only covers about 95% of the cases, since any UDT with
an implicit conversion from int will still generate the warnings. It would
be really nice to find a more general fix. Can anyone think of one?

Thanks,
-Dave

-------

*** composite_traits.hpp.~1.13.~ Sat Jan 19 18:58:04 2002
--- composite_traits.hpp Thu Jan 31 05:04:42 2002
***************
*** 343,348 ****
--- 343,368 ----
           ::boost::is_convertible<r_type, detail::int_convertible>::value
>::value));
  };
+
+ // Specializations suppress some nasty warnings with GCC
+ template<>
+ struct is_enum<float>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = false);
+ };
+
+ template<>
+ struct is_enum<double>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = false);
+ };
+
+ template<>
+ struct is_enum<long double>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = false);
+ };
+
  #else // __BORLANDC__
  //
  // buggy is_convertible prevents working

-------

*** conversion_traits.hpp.~1.14.~ Mon Jan 21 00:49:18 2002
--- conversion_traits.hpp Thu Jan 31 04:59:56 2002
***************
*** 156,161 ****
--- 156,184 ----
     void foo(); // avoid warning about all members being private
  };

+ // Declare specializations of is_convertible for all of the floating
+ // types to all of the integral types. This suppresses some nasty
+ // warnings
+
+ # define BOOST_IS_CONVERTIBLE(T1,T2) template<>struct
is_convertible<T1,T2>{static const bool value=true;};
+ # define BOOST_IS_CONVERTIBLE2(T1,T2) \
+ BOOST_IS_CONVERTIBLE(T1,signed T2) \
+ BOOST_IS_CONVERTIBLE(T1,unsigned T2)
+
+ # define BOOST_FLOAT_IS_CONVERTIBLE(F) \
+ BOOST_IS_CONVERTIBLE(F,char) \
+ BOOST_IS_CONVERTIBLE2(F,char) \
+ BOOST_IS_CONVERTIBLE2(F,short) \
+ BOOST_IS_CONVERTIBLE2(F,int) \
+ BOOST_IS_CONVERTIBLE2(F,long) \
+ BOOST_IS_CONVERTIBLE2(F,long long)
+
+ BOOST_FLOAT_IS_CONVERTIBLE(float)
+ BOOST_FLOAT_IS_CONVERTIBLE(double)
+ BOOST_FLOAT_IS_CONVERTIBLE(long double)
+ # undef BOOST_FLOAT_IS_CONVERTIBLE
+ # undef BOOST_IS_CONVERTIBLE2
+ # undef BOOST_IS_CONVERTIBLE
  #else

  template <class From, class To>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk