$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r72571 - sandbox/conversion/libs/conversion_ext/test
From: vicente.botet_at_[hidden]
Date: 2011-06-13 13:21:16
Author: viboes
Date: 2011-06-13 13:21:15 EDT (Mon, 13 Jun 2011)
New Revision: 72571
URL: http://svn.boost.org/trac/boost/changeset/72571
Log:
Conversion: Make a distiction between implicit and explicit converter
Text files modified: 
   sandbox/conversion/libs/conversion_ext/test/array.cpp     |     2                                         
   sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp |   177 ++++++++++++++++++++++++++++++++++++--- 
   sandbox/conversion/libs/conversion_ext/test/intrinsec.cpp |   148 ++++++++++++++++++++++++--------        
   sandbox/conversion/libs/conversion_ext/test/pair.cpp      |     6 +                                       
   4 files changed, 279 insertions(+), 54 deletions(-)
Modified: sandbox/conversion/libs/conversion_ext/test/array.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/array.cpp	(original)
+++ sandbox/conversion/libs/conversion_ext/test/array.cpp	2011-06-13 13:21:15 EDT (Mon, 13 Jun 2011)
@@ -8,9 +8,9 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
+#include <iostream>
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/boost/array.hpp>
-#include <iostream>
 #include <boost/detail/lightweight_test.hpp>
 #include "helper.hpp"
 #include <boost/static_assert.hpp>
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-13 13:21:15 EDT (Mon, 13 Jun 2011)
@@ -8,7 +8,9 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
+#include <boost/conversion/explicit_convert_to.hpp>
 #include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/assign_to.hpp>
 #include <boost/conversion/ca_wrapper.hpp>
 #include <boost/conversion/convertible_to.hpp>
 #include <boost/conversion/convertible_from.hpp>
@@ -20,6 +22,7 @@
 
 
 using namespace boost;
+using namespace boost::conversion;
 
 struct A{};
 struct B{
@@ -27,19 +30,9 @@
 };
 struct C{};
 
-void f(B) {}
-
-void g(boost::conversion::convertible_to<B> cb)
-{
-  cb.get().k();
-  return f(cb);
-}
-
-
-
 
 #if defined(BOOST_CONVERSION_DOUBLE_CP)
-  A convert_to(const B&, boost::conversion::dummy::type_tag<A> const&) {
+  A convert_to(const B&, dummy::type_tag<A> const&) {
     return A();
   }
 
@@ -47,7 +40,7 @@
     return to;
   }
 
-  B convert_to(const C&, boost::conversion::dummy::type_tag<B> const&) {
+  B convert_to(const C&, dummy::type_tag<B> const&) {
     return B();
   }
 
@@ -81,12 +74,163 @@
 #endif
 
 
+  void f(B) {}
+
+  void g(convertible_to<B> cb)
+  {
+    cb.get().k(); // need for get()
+    return f(cb); // implicit conversion from cb to B applies
+  }
+
   template <typename T>
   typename boost::enable_if<boost::is_extrinsic_convertible<T,B>, void >::type
   h(T v)
   {
-    return f(boost::conversion::convert_to<B>(v));
+    return f(convert_to<B>(v));
+  }
+
+//////////
+struct X{};
+
+struct ICF_X {
+};
+
+namespace boost {
+  namespace conversion {
+    template <>
+    struct converter_cp< ICF_X, X > : true_type {
+      ICF_X operator()(X const &)
+      {
+        return ICF_X();
+      }
+    };
   }
+}
+
+struct ECF_X {
+};
+
+namespace boost {
+  namespace conversion {
+    template <>
+    struct explicit_converter_cp< ECF_X, X > : true_type {
+      ECF_X operator()(X const &)
+      {
+        return ECF_X();
+      }
+    };
+  }
+}
+
+struct ICT_X {
+};
+
+namespace boost {
+  namespace conversion {
+    template <>
+    struct converter_cp< X, ICT_X > : true_type {
+      X operator()(ICT_X const &)
+      {
+        return X();
+      }
+    };
+  }
+}
+
+struct ECT_X {
+};
+
+namespace boost {
+  namespace conversion {
+    template <>
+    struct explicit_converter_cp< X, ECT_X > : true_type {
+      X operator()(ECT_X const &)
+      {
+        return X();
+      }
+    };
+  }
+}
+
+
+struct AF_X {
+};
+
+namespace boost {
+  namespace conversion {
+    template <>
+    struct assigner_cp< AF_X, X > : true_type {
+      AF_X& operator()(AF_X &lhs, X const&)
+      {
+        return lhs;
+      }
+    };
+  }
+}
+
+//////////////////////////
+
+  void xconvert_to_with_implicit_constructor()
+  {
+    {
+      X x;
+      ICF_X y1(convert_to<ICF_X>(x));
+      ICF_X y2(mcf(x));
+      mat(y2) = x;
+    }
+  }
+
+  #define BOOST_CONVERSION_CONSTRUCT(T, VAR, EXPR) \
+    T VAR(boost::conversion::explicit_convert_to<T>(EXPR))
+
+  void xconvert_to_with_explicit_constructor()
+  {
+    {
+      X x;
+      //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));
+      //ECF_X y1_2(mcf(x)); // fail as there is no implicit conversion.
+      ECF_X y2 = explicit_convert_to<ECF_X>(x);
+      //mat(y2) = x; // fails as no implicit conversion
+    }
+
+  }
+
+  void xconvert_to_with_implicit_conversion_operator()
+  {
+    {
+      ICT_X y;
+      X x1(convert_to<X>(y));
+      X x2(mcf(y));
+      X x3=convert_to<X>(y);
+      X x4=mcf(y);
+      mat(x4) = y;
+    }
+
+  }
+  void xconvert_to_with_explicit_conversion_operator()
+  {
+    {
+      ECT_X y;
+      X x1(explicit_convert_to<X>(y));
+      X x2=explicit_convert_to<X>(y);
+    }
+  }
+  void xassign_to_with_assignemet_operator()
+  {
+    {
+      X x;
+      //AF_X y1(x);  // compile fails
+      AF_X y2;
+      //y2=x;  // compile fails
+      assign_to(y2,x);
+      mat(y2)=x;
+    }
+  }
+////
+
+
 
 void explicit_convert_to() {
   using namespace boost::conversion;
@@ -119,7 +263,7 @@
 
 void implicit_conversion_via_mca() {
   C c;
-  f(boost::conversion::mca(c));
+  f(mca(c));
 }
 
 void implicit_conversion_via_mcf() {
@@ -141,6 +285,11 @@
 
 int main( )
 {
+  xconvert_to_with_implicit_constructor();
+  xconvert_to_with_explicit_constructor();
+  xconvert_to_with_implicit_conversion_operator();
+  xconvert_to_with_explicit_conversion_operator();
+  xassign_to_with_assignemet_operator();
   explicit_convert_to();
   explicit_assign_to();
   explicit_chain_assign_to();
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-13 13:21:15 EDT (Mon, 13 Jun 2011)
@@ -8,12 +8,17 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
+#include <boost/conversion/explicit_convert_to.hpp>
 #include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/assign_to.hpp>
 #include <boost/conversion/ca_wrapper.hpp>
+#include <boost/conversion/assignable_to.hpp>
+#include <boost/conversion/convertible_from.hpp>
 #include <iostream>
 #include <boost/detail/lightweight_test.hpp>
 
 using namespace boost;
+using namespace boost::conversion;
 
 struct B{};
 struct A {
@@ -21,16 +26,17 @@
     A(const B&){}
 };
 struct AE {
-    explicit AE(const B&){}
+    explicit AE(B){}
 };
 struct AA {
   AA(int){}
   AA(const A&){}
   AA& operator=(const A&) { return *this;}
+  //AA& operator=(const B&) { return *this;}
 };
 
 struct C {
-    operator B()  const{return B();}
+    operator B()  const{ return B(); }
 };
 struct CC {
   CC(int){}
@@ -38,42 +44,104 @@
   CC& operator=(const B&) { return *this;}
 };
 
-void convert_to_with_implicit_constructor() {
-    {
-    B b;
-    A a(b);
-    }
-    {
-    B b;
-    A a(boost::conversion::convert_to<A>(b));
-    }
+//////////
+struct X{};
 
-}
-void convert_to_with_explicit_constructor() {
-    {
-    B b;
-    AE ae(b);
-    }
-    {
-    B b;
-    AE ae(boost::conversion::convert_to<AE>(b));
-    }
+struct ICF_X {
+  ICF_X(X const&) {}
+};
+struct ECF_X {
+  explicit ECF_X(X const&) {}
+};
+
+struct ICT_X {
+    operator X()  const{ return X(); }
+};
+
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+struct ECT_X {
+    explicit operator X() const { return X(); }
+};
+#endif
+
+struct AF_X {
+  AF_X& operator=(X) { return *this; }
+};
+
+//////////////////////////
+
+void convert_to_with_implicit_constructor()
+{
+  {
+    X x;
+    ICF_X y1(x);
+    ICF_X y2 = x;
+  }
+  {
+    X x;
+    ICF_X y(convert_to<ICF_X>(x));
+  }
+}
+
+#define BOOST_CONVERSION_CONSTRUCT(T, VAR, EXPR) \
+  T VAR(boost::conversion::explicit_convert_to<T>(EXPR))
+
+void explicit_convert_to_with_explicit_constructor() {
+  {
+    X x;
+    ECF_X y1(x);
+    //ECF_X y2=x; // compile fails
+    ECF_X y2=ECF_X(x);
+  }
+  {
+    X x;
+    //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));
+    ECF_X y1_2(mcf(x)); // doesn't fail as there is the constructor from X, but will fails for extrinsic conversion.
+    ECF_X y2 = explicit_convert_to<ECF_X>(x);
+  }
 
 }
 
-void convert_to_with_conversion_operator() {
-    {
-    C c;
-    A a(c);
-    }
-    {
-    C c;
-    A a(boost::conversion::convert_to<A>(c));
-    }
+void convert_to_with_implicit_conversion_operator() {
+  {
+    ICT_X y;
+    X x1(y);
+    X x2=y;
+  }
+  {
+    ICT_X y;
+    X x1(convert_to<X>(y));
+    X x2=convert_to<X>(y);
+  }
+}
+void explicit_convert_to_with_explicit_conversion_operator() {
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+#error
+  {
+    ECT_X y;
+    X x1(y);
+    X x2=X(y);
+  }
+  {
+    ECT_X y;
+    X x1(explicit_convert_to<X>(y));
+    X x2=explicit_convert_to<X>(y);
+  }
+#endif
 
 }
 void assign_to_with_assignemet_operator() {
-    {
+  {
+    X x;
+    //AF_X y1(x);  // compile fails
+    AF_X y2;
+    y2=x;
+    assign_to(y2,x);
+    mat(y2)=x;
+  }
+  {
     A a(0);
     AA aa(0);
     aa=a;
@@ -81,13 +149,14 @@
     {
     A a(0);
     AA aa(0);
-    boost::conversion::assign_to(aa,a);
+    assign_to(aa,a);
     }
+
 }
 void mca_with_assignemet_operator() {
     A a(0);
     AA aa(0);
-    boost::conversion::mca(aa) =a;
+    mca(aa) =a;
 }
 
 void assign_to_with_assignemet_operator_and_implicit_constructor() {
@@ -99,13 +168,13 @@
     {
     B b;
     AA aa(1);
-    boost::conversion::assign_to(aa,b);
+    assign_to(aa,b);
     }
 }
 void mca_with_assignemet_operator_and_implicit_constructor() {
     B b;
     AA aa(1);
-    boost::conversion::mca(aa)=b;
+    mca(aa)=b;
 }
 
 void assign_to_with_assignemet_operator_and_conversion_operator() {
@@ -117,22 +186,23 @@
     {
     C c;
     CC cc(1);
-    boost::conversion::assign_to(cc,c);
+    assign_to(cc,c);
     }
 }
 
 void mca_with_assignemet_operator_and_conversion_operator() {
     C c;
     CC cc(1);
-    boost::conversion::mca(cc)=c;
+    mca(cc)=c;
 }
 
 
 int main( )
 {
   convert_to_with_implicit_constructor();
-  convert_to_with_explicit_constructor();
-  convert_to_with_conversion_operator();
+  explicit_convert_to_with_explicit_constructor();
+  convert_to_with_implicit_conversion_operator();
+  explicit_convert_to_with_explicit_conversion_operator();
   assign_to_with_assignemet_operator();
   assign_to_with_assignemet_operator_and_implicit_constructor();
   assign_to_with_assignemet_operator_and_conversion_operator();
Modified: sandbox/conversion/libs/conversion_ext/test/pair.cpp
==============================================================================
--- sandbox/conversion/libs/conversion_ext/test/pair.cpp	(original)
+++ sandbox/conversion/libs/conversion_ext/test/pair.cpp	2011-06-13 13:21:15 EDT (Mon, 13 Jun 2011)
@@ -15,6 +15,11 @@
 #include <boost/detail/lightweight_test.hpp>
 #include "helper.hpp"
 #include <boost/static_assert.hpp>
+#include <boost/conversion/type_traits/is_convertible.hpp>
+#include <boost/conversion/type_traits/is_constructible.hpp>
+#include <boost/conversion/type_traits/is_explicitly_convertible.hpp>
+#include <boost/conversion/type_traits/is_assignable.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
 
 using namespace boost;
 
@@ -24,6 +29,7 @@
 BOOST_STATIC_ASSERT(( boost::is_extrinsic_convertible<B2, A2>::value));
 BOOST_STATIC_ASSERT(( !boost::is_constructible<std::pair<A1,A2>, std::pair<B1,B2> >::value));
 BOOST_STATIC_ASSERT(( !boost::is_explicitly_convertible<std::pair<B1,B2>, std::pair<A1,A2> >::value));
+BOOST_STATIC_ASSERT(( !boost::is_convertible<std::pair<B1,B2>, std::pair<A1,A2> >::value));
 
 BOOST_STATIC_ASSERT(( !boost::is_assignable<B1, A1>::value));
 BOOST_STATIC_ASSERT(( !boost::is_assignable<B2, A2>::value));