Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72299 - in sandbox/conversion/boost/conversion: . boost
From: vicente.botet_at_[hidden]
Date: 2011-05-31 03:43:27


Author: viboes
Date: 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
New Revision: 72299
URL: http://svn.boost.org/trac/boost/changeset/72299

Log:
Conversion: Simplifying assign_to overloading
Text files modified:
   sandbox/conversion/boost/conversion/assign_to.hpp | 63 +++++++++++++++++----------------------
   sandbox/conversion/boost/conversion/boost/array.hpp | 3 -
   sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp | 4 -
   sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp | 4 -
   sandbox/conversion/boost/conversion/boost/interval.hpp | 4 -
   sandbox/conversion/boost/conversion/boost/optional.hpp | 4 -
   sandbox/conversion/boost/conversion/boost/rational.hpp | 4 -
   sandbox/conversion/boost/conversion/boost/tuple.hpp | 4 -
   sandbox/conversion/boost/conversion/convert_to.hpp | 2
   9 files changed, 36 insertions(+), 56 deletions(-)

Modified: sandbox/conversion/boost/conversion/assign_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/assign_to.hpp (original)
+++ sandbox/conversion/boost/conversion/assign_to.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -13,18 +13,13 @@
  Defines the free function @c assign_to.
 
 The function @c assign_to assigns the @c from parameter to the @c to parameter.
-The default implementation applies the the assignment operator of the @c To class.
-A user adapting another type could need to specialize the @c assign_to free function if the default behavior is not satisfactory.
+The default implementation uses the @c convert_to to convert the source to the target and use the copy assignment of the @c Target class.
 
+A user adapting another type could need to specialize the @c assign_to free function if the default behavior is not satisfactory.
 The user can add the @c assign_to overloading on the namespace of the Source or Target classes.
 But sometimes as it is the case for the standard classes, we can not add new functions on the std namespace,
-so we need a different technique.
-
-The technique consists in partially specialize on the function @c assign_to on the @c boost::conversion namespace.
-For compilers for which we can not partially specialize a function a trick is used:
-instead of calling directly to the @c assign_to member function, @c assign_to calls to the static operation apply
-on a class with the same name in the namespace @c overload_workaround.
-Thus the user can specialize partially this class.
+so we need a different technique. The technique consists in partially specialize on the function @c assign_to on
+the @c boost::conversion::overload_workaround namespace.
 
  */
 
@@ -70,32 +65,34 @@
         }
       };
     }
+ }
 
 #if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
- namespace impl_2 {
+ namespace conversion_impl_2 {
 
- //! @brief Default @c assign_to overload, used when ADL fails.
- //!
- //! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator.
- //! @Throws Whatever the underlying the assignment operator of the @c To class throws.
- //! Forwards the call to the overload workaround, which can yet be specialized by the user for standard C++ types.
- template < typename To, typename From >
- To& assign_to(To& to, const From& from, dummy::type_tag<To> const&)
- {
- return conversion::overload_workaround::assign_to<To,From>::apply(to, from);
- }
+ //! @brief Default @c assign_to overload, used when ADL fails.
+ //!
+ //! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator.
+ //! @Throws Whatever the underlying the assignment operator of the @c To class throws.
+ //! Forwards the call to the overload workaround, which can yet be specialized by the user for standard C++ types.
+ template < typename To, typename From >
+ To& assign_to(To& to, const From& from)
+ {
+ return conversion::overload_workaround::assign_to<To,From>::apply(to, from);
     }
+ }
 
- namespace impl {
- template <typename Target, typename Source>
- Target& assign_to_impl(Target& to, const Source& from)
- {
- using namespace boost::conversion::impl_2;
- //use boost::conversion::assign_to if ADL fails
- return assign_to(to, from, dummy::type_tag<Target>());
- }
+ namespace conversion_impl {
+ template <typename Target, typename Source>
+ Target& assign_to_impl(Target& to, const Source& from)
+ {
+ using namespace boost::conversion_impl_2;
+ //use boost::conversion::assign_to if ADL fails
+ return assign_to(to, from);
     }
+ }
 #endif
+ namespace conversion {
 
     //! @brief Extrinsic assign function.
     //! @tparam Target target type of the conversion.
@@ -104,19 +101,15 @@
     //! @Params
     //! @Param{to,target of the conversion}
     //! @Param{from,source of the conversion}
- //! @Param{p,a dummy parameter used to allow overloading on the Target type}
 
     //! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator.
     //! @Throws Whatever the underlying the assignment operator of the @c To class throws..
     //! This function can be overloaded by the user.
- //! A trick is used to overload on the return type by adding a defaulted dummy parameter.
- //! Specializations must overload on @c dummy::type_tag<Target>
 
     template <typename Target, typename Source>
- Target& assign_to(Target& to, const Source& from, dummy::base_tag<Target> const& p =dummy::base_tag<Target>())
+ Target& assign_to(Target& to, const Source& from)
     {
- (void)p;
- return boost::conversion::impl::assign_to_impl<Target, Source>(to, from);
+ return boost::conversion_impl::assign_to_impl<Target, Source>(to, from);
     }
   }
 }

Modified: sandbox/conversion/boost/conversion/boost/array.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/array.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/array.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -72,7 +72,6 @@
   //! @Returns The @c to parameter reference.
   template < typename T1, typename T2, std::size_t N>
   inline array<T1,N>& assign_to(array<T1,N>& to, array<T2,N> const & from
- , conversion::dummy::type_tag<array<T1,N> > const&
   )
   {
     for (unsigned int i =0; i<N; ++i)

Modified: sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/chrono_duration_to_posix_time_duration.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -108,7 +108,6 @@
 
     template < class Rep, class Period>
     inline chrono::duration<Rep, Period> & assign_to(chrono::duration<Rep, Period> & to, const posix_time::time_duration& from
- , conversion::dummy::type_tag<chrono::duration<Rep, Period> > const&
     )
 
     {
@@ -135,7 +134,6 @@
     //! @Returns The @c to parameter reference.
     template < class Rep, class Period>
     inline time_duration& assign_to(time_duration& to, const chrono::duration<Rep, Period>& from
- , conversion::dummy::type_tag<posix_time::time_duration> const&
     )
     {
         to = boost::conversion::convert_to<time_duration>(from);

Modified: sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/chrono_time_point_to_posix_time_ptime.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -99,7 +99,6 @@
 
         template < class Clock, class Duration>
         inline chrono::time_point<Clock, Duration>& assign_to(chrono::time_point<Clock, Duration>& to, const posix_time::ptime& from
- , conversion::dummy::type_tag<chrono::time_point<Clock, Duration> > const&
         )
         {
             to = boost::conversion::convert_to<chrono::time_point<Clock, Duration> >(from);
@@ -122,7 +121,6 @@
 
         template < class Clock, class Duration>
         inline ptime& assign_to(ptime& to, const chrono::time_point<Clock, Duration>& from
- , conversion::dummy::type_tag<posix_time::ptime> const&
         )
         {
             to = boost::conversion::convert_to<ptime>(from);

Modified: sandbox/conversion/boost/conversion/boost/interval.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/interval.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/interval.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -57,10 +57,8 @@
         }
         template < class T, class PT, class U, class PU>
         inline interval<T,PT>& assign_to(interval<T,PT>& to, const interval<U,PU>& from
- , boost::conversion::dummy::type_tag<interval<T,PT> > const&p=boost::conversion::dummy::type_tag<interval<T,PT> >()
         )
         {
- (void)p; // warning removal
           to.assign(boost::conversion::convert_to<T>(from.lower()),boost::conversion::convert_to<U>(from.upper()));
           return to;
         }

Modified: sandbox/conversion/boost/conversion/boost/optional.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/optional.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/optional.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -125,10 +125,8 @@
   //! @Returns The @c to parameter reference.
   template < class Target, class Source>
   inline optional<Target>& assign_to(optional<Target>& to, const optional<Source>& from
- , conversion::dummy::type_tag<optional<Target> > const&p=conversion::dummy::type_tag<optional<Target> >()
   )
   {
- (void)p; // warning removal
     to = boost::conversion::convert_to<optional<Target> >(from);
     //to = from?optional<Target>(boost::conversion::convert_to<Target>(from.get())):optional<Target>();
     return to;

Modified: sandbox/conversion/boost/conversion/boost/rational.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/rational.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/rational.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -75,10 +75,8 @@
 
     template < class T, class U>
     inline rational<T>& assign_to(rational<T>& to, const rational<U>& from
- , conversion::dummy::type_tag<rational<T> > const& p=conversion::dummy::type_tag<rational<T> >()
                         )
     {
- (void)p; // warning removal
       to.assign(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
       return to;
     }

Modified: sandbox/conversion/boost/conversion/boost/tuple.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/tuple.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/tuple.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //
@@ -87,7 +87,6 @@
 
     template < class T1, class T2, class U1, class U2>
     inline tuple<T1,T2>& assign_to(tuple<T1,T2>& to, tuple<U1,U2> const & from
- , conversion::dummy::type_tag<tuple<T1,T2> > const&
     )
     {
         to = boost::conversion::convert_to<boost::fusion::tuple<T1,T2> >(from);
@@ -108,7 +107,6 @@
 
     template < class T1, class T2, class T3, class U1, class U2, class U3>
     inline tuple<T1,T2,T3> assign_to(tuple<T1,T2,T3>& to, boost::fusion::tuple<U1,U2,U3> const & from
- , conversion::dummy::type_tag<tuple<T1,T2,T3> > const&
     )
     {
         to = boost::conversion::convert_to<boost::fusion::tuple<T1,T2> >(from);

Modified: sandbox/conversion/boost/conversion/convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/convert_to.hpp 2011-05-31 03:43:25 EDT (Tue, 31 May 2011)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////////////
 //
-// (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost
+// (C) Copyright Vicente J. Botet Escriba 2009-2011. Distributed under the Boost
 // Software License, Version 1.0. (See accompanying file
 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 //


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