Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72553 - sandbox/conversion/boost/conversion
From: vicente.botet_at_[hidden]
Date: 2011-06-12 09:52:53


Author: viboes
Date: 2011-06-12 09:52:52 EDT (Sun, 12 Jun 2011)
New Revision: 72553
URL: http://svn.boost.org/trac/boost/changeset/72553

Log:
Conversion: Added enablers on wrappers for convertible from/to and assignable_to
Text files modified:
   sandbox/conversion/boost/conversion/assignable_to.hpp | 53 +++++++++++++++++++++++++++------------
   sandbox/conversion/boost/conversion/convertible_from.hpp | 10 ++++++
   sandbox/conversion/boost/conversion/convertible_to.hpp | 9 ++++++
   3 files changed, 53 insertions(+), 19 deletions(-)

Modified: sandbox/conversion/boost/conversion/assignable_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/assignable_to.hpp (original)
+++ sandbox/conversion/boost/conversion/assignable_to.hpp 2011-06-12 09:52:52 EDT (Sun, 12 Jun 2011)
@@ -18,6 +18,9 @@
 
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/assign_to.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_assignable.hpp>
+#include <boost/utility/enable_if.hpp>
 
 namespace boost {
   namespace conversion {
@@ -37,15 +40,19 @@
       //! @NoThrow.
       assignable_to(Target& r) : ref_(r) {}
 
- //! Implicit conversion to @c U.
- //! @Effects Forwards the conversion from the reference using @c conver_to.
- //! @Returns @c *this
- //! @Throws Whatever @c convert_to throws.
- template <typename U>
- operator U()
- {
- return boost::conversion::convert_to<U>(ref_);
- }
+// //! Implicit conversion to @c U.
+// //! @Effects Forwards the conversion from the reference using @c conver_to.
+// //! @Returns @c *this
+// //! @Throws Whatever @c convert_to throws.
+// template <typename U
+//#if defined(BOOST_CONVERSION_ENABLE_CND) && !defined(BOOST_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS)
+// , typename boost::enable_if< boost::is_extrinsic_convertible<Target,U>, int >::type = 0
+//#endif
+// >
+// operator U()
+// {
+// return boost::conversion::convert_to<U>(ref_);
+// }
 
       //! Assignment.
       //!
@@ -58,25 +65,37 @@
         return *this;
       }
 
- //! Assignment from a converter assigner wrapping a type U convertible to Target.
+ //! Assignment from a assignable_to wrapping a type @c Source convertible to Target.
       //!
- //! @Effects Forwards the assignment to the reference using assign_to.
+ //! @Effects Forwards the assignment to the reference using @c assign_to.
       //! @Returns @c *this
       //! @Throws Whatever @c assign_to throws.
- template <typename U>
- assignable_to& operator =(assignable_to<U> const& u)
+ //! @Remark This constructor doesn't participates on overload resolution if @c Source is not extrinsic assignable to @c Target.
+ template <typename Source>
+#if defined(BOOST_CONVERSION_ENABLE_CND) && !defined(BOOST_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS)
+ typename boost::enable_if< boost::is_extrinsic_assignable<Target,Source>, assignable_to& >::type
+#else
+ assignable_to&
+#endif
+ operator =(assignable_to<Source> const& s)
       {
- boost::conversion::assign_to(ref_, u.ref_);
+ boost::conversion::assign_to(ref_, s.ref_);
         return *this;
       }
 
- //! Assignment from a type Source assignable to Target.
+ //! Assignment from a type @c Source assignable to @c Target.
       //!
- //! @Effects Forwards the assignment to the reference using assign_to
+ //! @Effects Forwards the assignment to the reference using @c assign_to
       //! @Returns @c *this
       //! @Throws Whatever @c assign_to throws.
+ //! @Remark This constructor doesn't participates on overload resolution if @c Source is not extrinsic assignable to @c Target.
       template <typename Source>
- assignable_to& operator =(Source const& u)
+#if defined(BOOST_CONVERSION_ENABLE_CND) && !defined(BOOST_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS)
+ typename boost::enable_if< boost::is_extrinsic_assignable<Target,Source>, assignable_to& >::type
+#else
+ assignable_to&
+#endif
+ operator =(Source const& u)
       {
         boost::conversion::assign_to(ref_, u);
         return *this;

Modified: sandbox/conversion/boost/conversion/convertible_from.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/convertible_from.hpp (original)
+++ sandbox/conversion/boost/conversion/convertible_from.hpp 2011-06-12 09:52:52 EDT (Sun, 12 Jun 2011)
@@ -18,6 +18,8 @@
 
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/assign_to.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
 
 namespace boost {
   namespace conversion {
@@ -37,7 +39,13 @@
       //! @Effects Forwards the conversion from the reference using @c conver_to.
       //! @Returns the conversion using @c conver_to
       //! @Throws Whatever extrinsic conversion from @c Source to @c Target could throw.
- template <typename Target>
+ //! @Remark On compilers that supports C++0x default arguments for function template parameters,
+ //! this constructor doesn't participates on overload resolution if @c Source is not extrinsic convertible to @c Target.
+ template <typename Target
+#if defined(BOOST_CONVERSION_ENABLE_CND) && !defined(BOOST_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS)
+ , typename boost::enable_if< boost::is_extrinsic_convertible<Source,Target>, int >::type = 0
+#endif
+ >
       operator Target() const
       {
         return conversion::convert_to<Target>(val_);

Modified: sandbox/conversion/boost/conversion/convertible_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/convertible_to.hpp (original)
+++ sandbox/conversion/boost/conversion/convertible_to.hpp 2011-06-12 09:52:52 EDT (Sun, 12 Jun 2011)
@@ -18,6 +18,8 @@
 
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/assign_to.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
 
 namespace boost {
   namespace conversion {
@@ -32,8 +34,13 @@
       //! constructor from a extrinsic implicitly convertible to @c Target.
       //! @Effects Store the extrinsic conversion from @c source to @ Target.
       //! @Throws Whatever extrinsic implicit conversion from @c source to @c Target could throw.
+ //! @Remark This constructor doesn't participates on overload resolution if @c Source is not extrinsic convertible to @c Target.
       template <typename Source>
- convertible_to(Source const& source)
+ convertible_to(Source const& source
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+ , typename enable_if<boost::is_extrinsic_convertible<Source,Target> >::type* dummy = 0
+#endif
+ )
         : val_(boost::conversion::convert_to<Target>(source))
       {}
 


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