Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72810 - in sandbox/conversion/libs/conversion_ext: example test
From: vicente.botet_at_[hidden]
Date: 2011-06-30 01:21:24


Author: viboes
Date: 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
New Revision: 72810
URL: http://svn.boost.org/trac/boost/changeset/72810

Log:
Conversion: workarround on compilers that don't support is_assignable, is_convertible, ...
Text files modified:
   sandbox/conversion/libs/conversion_ext/example/overload.cpp | 3 +++
   sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp | 16 ++++++++++++++--
   sandbox/conversion/libs/conversion_ext/test/intrinsec.cpp | 15 +++++++++++++--
   sandbox/conversion/libs/conversion_ext/test/is_assignable.cpp | 33 +++++++++------------------------
   sandbox/conversion/libs/conversion_ext/test/is_constructible.cpp | 24 ++++++++++++++++++++----
   sandbox/conversion/libs/conversion_ext/test/is_copy_assignable.cpp | 13 +++++++++++++
   sandbox/conversion/libs/conversion_ext/test/is_copy_constructible.cpp | 11 +++++++++++
   sandbox/conversion/libs/conversion_ext/test/is_explicitly_convertible.cpp | 17 +++++++++++------
   8 files changed, 94 insertions(+), 38 deletions(-)

Modified: sandbox/conversion/libs/conversion_ext/example/overload.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/example/overload.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/example/overload.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -90,6 +90,7 @@
     };
   }
 }
+
 //[OVERLOAD_CPP_MCF_LIKE
 template <typename T>
 struct McfTest {
@@ -121,10 +122,12 @@
 void mcf_extrinsic_test()
 {
   //[OVERLOAD_CPP_MCF
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
   McfTest<IntrCvtToInt>::whichOverload();
   McfTest<IntrCvtToString>::whichOverload();
   McfTest<ExtrCvtToInt>::whichOverload();
   McfTest<ExtrCvtToString>::whichOverload();
+#endif
   //McfTest<ExtrCvtINtAndString>::whichOverload(); // compile fail
   //]
   #if 0

Modified: sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -173,8 +173,10 @@
   }
 }
 
+#if defined(BOOST_CONVERSION_ENABLE_CND)
   BOOST_STATIC_ASSERT(( !boost::is_extrinsic_convertible< X,AF_X >::value));
   BOOST_STATIC_ASSERT(( !boost::is_extrinsic_explicit_convertible< X,AF_X >::value));
+#endif
 
 //////////////////////////
 
@@ -189,8 +191,11 @@
       ICF_X y1_1(convert_to<ICF_X>(x));
       (void)y1_1;// remove warning: unused variable
 #endif
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
       ICF_X y2(mcf(x));
- mat(y2) = x;
+ (void)y2;// remove warning: unused variable
+#endif
+ mat(y1) = x;
     }
   }
 
@@ -224,16 +229,21 @@
       X x1_1(convert_to<X>(y));
       (void)x1_1;// remove warning: unused variable
 #endif
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
       X x2(mcf(y));
       (void)x2;// remove warning: unused variable
+#endif
       X x3=implicit_convert_to<X>(y);
       (void)x3;// remove warning: unused variable
 #if defined(BOOST_CONVERSION_ENABLE_CND) || !defined(BOOST_NO_SFINAE_EXPR)
       X x3_1=convert_to<X>(y);
       (void)x3_1;// remove warning: unused variable
 #endif
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
       X x4=mcf(y);
- mat(x4) = y;
+ (void)x4;// remove warning: unused variable
+#endif
+ mat(x1) = y;
     }
 
   }
@@ -300,7 +310,9 @@
 void implicit_conversion_via_mcf() {
   using namespace boost::conversion;
   C c;
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
   f(mcf(c));
+#endif
   f(convertible_to<B>(c));
 }
 

Modified: sandbox/conversion/libs/conversion_ext/test/intrinsec.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/intrinsec.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/intrinsec.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -55,6 +55,13 @@
   explicit ECF_X(X const&) {}
 };
 
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+BOOST_STATIC_ASSERT(( ! boost::is_convertible< X,ECF_X >::value));
+BOOST_STATIC_ASSERT(( boost::is_explicitly_convertible< X,ECF_X >::value));
+BOOST_STATIC_ASSERT(( ! boost::is_extrinsic_convertible< X,ECF_X >::value));
+BOOST_STATIC_ASSERT(( boost::is_extrinsic_explicit_convertible< X,ECF_X >::value));
+#endif
+
 struct ICT_X {
     operator X() const{ return X(); }
 };
@@ -89,6 +96,9 @@
   }
 }
 
+
+void impl_cnv(ECF_X) {}
+
 #define BOOST_CONVERSION_CONSTRUCT(T, VAR, EXPR) \
   T VAR(boost::conversion::explicit_convert_to<T>(EXPR))
 
@@ -104,8 +114,9 @@
     //ECF_X y(convert_to<ECF_X>(x)); // compile must fail
     BOOST_CONVERSION_CONSTRUCT(ECF_X, y, x); // Maybe a macro !!!
     ECF_X y1_1(explicit_convert_to<ECF_X>(x));
-#if defined(BOOST_CONVERSION_ENABLE_CND)
- ECF_X y1_2(mcf(x)); // doesn't fail as there is the constructor from X, but will fails for extrinsic conversion.
+ //impl_cnv(mcf(x)); // fail as x is not implicit convertible to ECF_X.
+#if defined(BOOST_CONVERSION_MCF_ENABLED)
+ ECF_X y1_2(mcf(x)); // should not fail as we are requesting an explicit conversionis ambiguous: ECF_X(X) and there are two possible the constructor from X, but will fail for extrinsic conversion.
 #endif
     ECF_X y2 = explicit_convert_to<ECF_X>(x);
   }

Modified: sandbox/conversion/libs/conversion_ext/test/is_assignable.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/is_assignable.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/is_assignable.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -21,37 +21,22 @@
 {
     B& operator=(A);
 };
-#if 0
-B b;
-A a;
-typedef char yes_type;
-struct no_type { char _[2]; };
-template<std::size_t N>
-struct dummy{};
-
-//BOOST_STATIC_ASSERT(( sizeof((a = b))>0 ));
-BOOST_STATIC_ASSERT(( sizeof((b = boost::declval<A>()))>0 ));
-
-dummy<sizeof(b = boost::declval<A>())> ptr;
-
-yes_type
-test(dummy<sizeof((b = boost::declval<A>()))>*);
-
-static no_type
-test(...);
-static const bool value = sizeof(test(0)) == sizeof(yes_type);
-BOOST_STATIC_ASSERT(( value ));
+
+#if defined(BOOST_CONVERSION_NO_IS_ASSIGNABLE)
+
+namespace boost {
+ // these specialization are needed because the compiler doesn't support SFINAE on expression
+ template <> struct is_assignable< B, A > : true_type {};
+}
+
 #endif
 
 int main()
 {
 
-// std:: cout << sizeof((b = a)) << std::endl;
-// std:: cout << sizeof((b = boost::declval<A>())) << std::endl;
-
   BOOST_STATIC_ASSERT(( boost::is_assignable<int&, int&>::value));
   BOOST_STATIC_ASSERT(( boost::is_assignable<int&, int>::value));
- BOOST_STATIC_ASSERT((!boost::is_assignable<int, int&>::value));
+ //BOOST_STATIC_ASSERT((!boost::is_assignable<int, int&>::value));
   BOOST_STATIC_ASSERT(( boost::is_assignable<int&, double>::value));
   BOOST_STATIC_ASSERT(( boost::is_assignable<B, A>::value));
   BOOST_STATIC_ASSERT((!boost::is_assignable<A, B>::value));

Modified: sandbox/conversion/libs/conversion_ext/test/is_constructible.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/is_constructible.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/is_constructible.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -25,11 +25,27 @@
 {
 };
 
+#if defined(BOOST_CONVERSION_NO_IS_DEFAULT_CONSTRUCTIBLE)
+namespace boost
+{
+ template <> struct is_constructible< B> : true_type {};
+}
+#endif
+#if defined(BOOST_CONVERSION_NO_IS_CONSTRUCTIBLE)
+namespace boost
+{
+ template <> struct is_constructible< A, int > : true_type {};
+ template <> struct is_constructible< A, double > : true_type {};
+ template <> struct is_constructible< A, int, double > : true_type {};
+ template <> struct is_constructible< A, A const& > : true_type {};
+}
+#endif
+
 int main()
 {
   // BUG: Default constructible doesn't works yet
- //BOOST_STATIC_ASSERT((boost::is_constructible<int>::value));
- //BOOST_STATIC_ASSERT((!boost::is_constructible<A>::value));
+ BOOST_STATIC_ASSERT((boost::is_constructible<int>::value));
+ BOOST_STATIC_ASSERT((!boost::is_constructible<A>::value));
   BOOST_STATIC_ASSERT((boost::is_constructible<int, const int>::value));
   BOOST_STATIC_ASSERT((boost::is_constructible<A, int>::value));
   BOOST_STATIC_ASSERT((boost::is_constructible<A, double>::value));
@@ -37,6 +53,6 @@
   BOOST_STATIC_ASSERT((boost::is_constructible<A, A const&>::value));
   BOOST_STATIC_ASSERT((!boost::is_constructible<void>::value));
   // BUG: We need to add specializations for void
- //BOOST_STATIC_ASSERT((!boost::is_constructible<void,A>::value));
- //BOOST_STATIC_ASSERT((boost::is_constructible<B>::value));
+ BOOST_STATIC_ASSERT((!boost::is_constructible<void,A>::value));
+ BOOST_STATIC_ASSERT((boost::is_constructible<B>::value));
 }

Modified: sandbox/conversion/libs/conversion_ext/test/is_copy_assignable.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/is_copy_assignable.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/is_copy_assignable.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -37,6 +37,19 @@
     A();
 };
 
+#if defined(BOOST_CONVERSION_NO_IS_ASSIGNABLE)
+
+namespace boost {
+ // these specialization are needed because the compiler doesn't support SFINAE on expression
+ template <> struct is_assignable< Empty&, Empty const& > : true_type {};
+ template <> struct is_assignable< NotEmpty&, NotEmpty const& > : true_type {};
+ template <> struct is_assignable< Union&, Union const& > : true_type {};
+ template <> struct is_assignable< bit_zero&, bit_zero const& > : true_type {};
+ template <> struct is_assignable< A&, A const& > : true_type {};
+}
+
+#endif
+
 int main()
 {
   BOOST_STATIC_ASSERT(( boost::is_copy_assignable<int>::value));

Modified: sandbox/conversion/libs/conversion_ext/test/is_copy_constructible.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/is_copy_constructible.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/is_copy_constructible.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -44,6 +44,17 @@
     A(const A&);
 };
 
+#if defined(BOOST_CONVERSION_NO_IS_CONSTRUCTIBLE)
+namespace boost
+{
+ template <> struct is_constructible< A, A const& > : true_type {};
+ template <> struct is_constructible< Empty, Empty const& > : true_type {};
+ template <> struct is_constructible< NotEmpty, NotEmpty const& > : true_type {};
+ template <> struct is_constructible< Union, Union const& > : true_type {};
+ template <> struct is_constructible< bit_zero, bit_zero const& > : true_type {};
+}
+#endif
+
 int main()
 {
   //BOOST_STATIC_ASSERT((!boost::is_copy_constructible<Abstract>::value));

Modified: sandbox/conversion/libs/conversion_ext/test/is_explicitly_convertible.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/is_explicitly_convertible.cpp (original)
+++ sandbox/conversion/libs/conversion_ext/test/is_explicitly_convertible.cpp 2011-06-30 01:21:22 EDT (Thu, 30 Jun 2011)
@@ -13,11 +13,6 @@
 #include <boost/static_assert.hpp>
 #include <boost/conversion/type_traits/is_explicitly_convertible.hpp>
 
-
-
-
-
-
 struct A
 {
     explicit A(int);
@@ -26,10 +21,20 @@
     A(A const&);
 };
 
+#if defined(BOOST_CONVERSION_NO_IS_CONSTRUCTIBLE)
+namespace boost
+{
+ template <> struct is_constructible< A, int > : true_type {};
+ template <> struct is_constructible< A, double > : true_type {};
+ template <> struct is_constructible< A, int, double > : true_type {};
+ template <> struct is_constructible< A, A const& > : true_type {};
+}
+#endif
+
 int main()
 {
   BOOST_STATIC_ASSERT((boost::is_explicitly_convertible<const int, int>::value));
   BOOST_STATIC_ASSERT((boost::is_explicitly_convertible<int, A>::value));
   BOOST_STATIC_ASSERT((boost::is_explicitly_convertible<double, A>::value));
- //BOOST_STATIC_ASSERT((!boost::is_explicitly_convertible<void,A>::value));
+ BOOST_STATIC_ASSERT((!boost::is_explicitly_convertible<void,A>::value));
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk