|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72551 - sandbox/conversion/libs/conversion_ext/test
From: vicente.botet_at_[hidden]
Date: 2011-06-12 08:48:49
Author: viboes
Date: 2011-06-12 08:48:49 EDT (Sun, 12 Jun 2011)
New Revision: 72551
URL: http://svn.boost.org/trac/boost/changeset/72551
Log:
Conversion: Added wrappers for convertible from/to and assignable_to
Text files modified:
sandbox/conversion/libs/conversion_ext/test/extrinsec.cpp | 91 +++++++++++++++++++++++++++++++++------
1 files changed, 76 insertions(+), 15 deletions(-)
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-12 08:48:49 EDT (Sun, 12 Jun 2011)
@@ -10,17 +10,34 @@
#include <boost/conversion/convert_to.hpp>
#include <boost/conversion/ca_wrapper.hpp>
+#include <boost/conversion/convertible_to.hpp>
+#include <boost/conversion/convertible_from.hpp>
+#include <boost/conversion/assignable_to.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
#include <iostream>
#include <boost/detail/lightweight_test.hpp>
+#include <boost/static_assert.hpp>
+
using namespace boost;
struct A{};
-struct B{};
+struct B{
+ void k(){}
+};
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&) {
return A();
@@ -57,36 +74,80 @@
}
}
#endif
+
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+ BOOST_STATIC_ASSERT(( boost::is_extrinsic_convertible< B,A >::value));
+ BOOST_STATIC_ASSERT(( boost::is_extrinsic_convertible< C,B >::value));
+#endif
+
+
+ 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));
+ }
+
void explicit_convert_to() {
+ using namespace boost::conversion;
B b;
- A a(boost::conversion::convert_to<A>(b));
+ A a(convert_to<A>(b));
+ (void)a;
+ C c;
+ f(convert_to<B>(c));
}
-void explicit_assign_to() {
- B b;
- A a;
- boost::conversion::assign_to(a, b);
- boost::conversion::mca(a)= b;
+void explicit_assign_to() {
+ using namespace boost::conversion;
+ B b;
+ A a;
+ assign_to(a, b);
+ mca(a)= b;
+ mat(a)= b;
}
-void explicit_chain_assign_to() {
- C c;
- B b;
- A a;
- boost::conversion::assign_to(a, boost::conversion::assign_to(b,c));
- boost::conversion::mca(a)= boost::conversion::mca(b) = c;
+void explicit_chain_assign_to() {
+ using namespace boost::conversion;
+ C c;
+ B b;
+ A a;
+ assign_to(a, assign_to(b,c));
+ mca(a)= mca(b) = c;
+ mat(a)= mat(b) = c;
}
+
void implicit_conversion_via_mca() {
- C c;
- f(boost::conversion::mca(c));
+ C c;
+ f(boost::conversion::mca(c));
}
+
+void implicit_conversion_via_mcf() {
+ using namespace boost::conversion;
+ C c;
+ f(mcf(c));
+ f(convertible_to<B>(c));
+}
+
+void implicit_conversion_via_convertible_to() {
+ C c;
+ g(c);
+}
+
+void implicit_conversion_via_sfinae() {
+ C c;
+ h(c);
+}
+
int main( )
{
explicit_convert_to();
explicit_assign_to();
explicit_chain_assign_to();
implicit_conversion_via_mca();
+ implicit_conversion_via_mcf();
+ implicit_conversion_via_convertible_to();
+ implicit_conversion_via_sfinae();
return boost::report_errors();
}
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