Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72296 - in sandbox/conversion/boost/conversion: . boost fp
From: vicente.botet_at_[hidden]
Date: 2011-05-31 03:15:35


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

Log:
Conversion: Allowing assign_to to be called by ADL
Text files modified:
   sandbox/conversion/boost/conversion/assign_to.hpp | 34 ++++++++++++++++-----
   sandbox/conversion/boost/conversion/boost/interval.hpp | 15 +++++---
   sandbox/conversion/boost/conversion/boost/optional.hpp | 50 ++++++++++++++++++++++--------
   sandbox/conversion/boost/conversion/boost/rational.hpp | 64 ++++++++++++++++++++++++++-------------
   sandbox/conversion/boost/conversion/convert_to.hpp | 29 ++++++++++++++++-
   sandbox/conversion/boost/conversion/fp/convert_to.hpp | 31 ++++++++++++++++---
   sandbox/conversion/boost/conversion/try_assign_to.hpp | 2
   sandbox/conversion/boost/conversion/try_convert_to.hpp | 24 ++++++++++++++
   8 files changed, 189 insertions(+), 60 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:15:31 EDT (Tue, 31 May 2011)
@@ -38,27 +38,33 @@
   namespace conversion {
     namespace overload_workaround {
       //! struct used when overloading can not be applied.
- template < typename To, typename From >
+ //! @tparam To target type of the conversion.
+ //! @tparam From source type of the conversion.
+ //! @tparam Enable A dummy parameter that can be used for SFINAE.
+ template < typename To, typename From, class Enable = void>
       struct assign_to
       {
         //! @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..
+ //! @Throws Whatever the underlying assignment operator of the @c To class throws.
         inline static To& apply(To& to, const From& from)
         {
- to = from;
+ to = ::boost::conversion::convert_to<To>(from);
           return to;
         }
       };
+
+ //! partial specialization for c-array types.
       template < typename To, typename From, std::size_t N >
       struct assign_to<To[N],From[N]>
       {
- //! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator on each one of the array elements.
- //! @Throws Whatever the underlying the assignment operator of the @c To class throws..
+ //! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator on each one of the array elements.
+ //! @Throws Whatever the underlying assignment operator of the @c To class throws.
+ //! @Basic
         inline static To*& apply(To(&to)[N], const From(& from)[N])
         {
           for (std::size_t i = 0; i < N; ++i)
           {
- to[i] = boost::conversion::convert_to<To>(from[i]);
+ to[i] = ::boost::conversion::convert_to<To>(from[i]);
           }
           return to;
         }
@@ -71,7 +77,7 @@
       //! @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..
+ //! @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&)
@@ -91,9 +97,21 @@
     }
 #endif
 
+ //! @brief Extrinsic assign function.
+ //! @tparam Target target type of the conversion.
+ //! @tparam Source source type of the conversion.
+ //!
+ //! @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 partially specialized on compilers supporting it.
+ //! 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>())
     {

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:15:31 EDT (Tue, 31 May 2011)
@@ -49,17 +49,20 @@
       //! @Returns the target interval having as extremes the conversion from the source interval extremes.
         template < class T, class PT, class U, class PU>
         inline interval<T,PT> convert_to(interval<U,PU> const & from
- , conversion::dummy::type_tag<interval<T,PT> > const&)
+ , ::boost::conversion::dummy::type_tag<interval<T,PT> > const&p=::boost::conversion::dummy::type_tag<interval<T,PT> >()
+ )
         {
- return interval<T,PT>(boost::conversion::convert_to<T>(from.lower()), boost::conversion::convert_to<U>(from.upper()));
+ (void)p; // warning removal
+ return interval<T,PT>(boost::conversion::convert_to<T>(from.lower()), boost::conversion::convert_to<U>(from.upper()));
         }
         template < class T, class PT, class U, class PU>
         inline interval<T,PT>& assign_to(interval<T,PT>& to, const interval<U,PU>& from
- , conversion::dummy::type_tag<interval<T,PT> > const&
- )
+ , boost::conversion::dummy::type_tag<interval<T,PT> > const&p=boost::conversion::dummy::type_tag<interval<T,PT> >()
+ )
         {
- to.assign(boost::conversion::convert_to<T>(from.lower()),boost::conversion::convert_to<U>(from.upper()));
- return to;
+ (void)p; // warning removal
+ to.assign(boost::conversion::convert_to<T>(from.lower()),boost::conversion::convert_to<U>(from.upper()));
+ return to;
         }
     }
     #endif

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:15:31 EDT (Tue, 31 May 2011)
@@ -23,10 +23,12 @@
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/assign_to.hpp>
 #include <boost/config.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/utility/enable_if.hpp>
 
 namespace boost {
 
- #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING && ! defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING && ! defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
   namespace conversion {
     namespace overload_workaround {
       template < class Target, class Source>
@@ -67,46 +69,66 @@
     }
   }
 #else
+ #if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ namespace conversion {
+ namespace detail {
+ template <typename T>
+ struct is_optional : mpl::false_ {};
+ template <typename T>
+ struct is_optional< ::boost::optional<T> > : mpl::true_ {};
 
+ }
+ }
+ #endif
   //! @brief @c convert_to overloading for source and target been @c boost::optional.
   //!
   //! @Returns If the optional source is initialized @c boost::optional<Target> initialized to the conversion of the optional value.
   //! Uninitialized @c boost::optional<Target otherwise.
   template < class Target, class Source>
- inline optional<Target> convert_to(optional<Source> const & from
- , conversion::dummy::type_tag<optional<Target> > const&)
+ inline
+ typename enable_if<typename conversion::detail::is_optional<Target>::type,Target>::type
+ convert_to(
+ optional<Source> const & from
+ , conversion::dummy::type_tag<Target> const&p=conversion::dummy::type_tag<Target>()
+ )
   {
- return (from?optional<Target>(boost::conversion::convert_to<Target>(from.get())):optional<Target>());
+ (void)p; // warning removal
+ return (from?Target(boost::conversion::convert_to<typename Target::value_type>(from.get())):Target());
   }
-
+
+#if 0
   //! @brief @c convert_to overloading to try to convert the source to the target.
   //!
- //! We can see this specialization as a try_convert_to function.
- //! @Returns If the source is convertible to the target @c boost::optional<Target> initialized to the result of the conversion.
+ //! We can see this overloading as a try_convert_to function.
+ //! @Returns If the source is convertible to the target @c value_type @c boost::optional<Target> initialized to the result of the conversion.
   //! Uninitialized @c boost::optional<Target otherwise.
   template < class Target, class Source>
- inline optional<Target> convert_to(Source const & from
- , conversion::dummy::type_tag<optional<Target> > const&)
+ inline
+ typename enable_if<typename conversion::detail::is_optional<Target>::type,Target>::type
+ convert_to(Source const & from
+ , conversion::dummy::type_tag<Target> const&p=conversion::dummy::type_tag<Target>()
+ )
   {
     try
     {
- return optional<Target>(boost::conversion::convert_to<Target>(from));
+ return Target(boost::conversion::convert_to<typename Target::value_type>(from));
     }
     catch (...)
     {
- return optional<Target>();
+ return Target();
     }
   }
-
+#endif
   //! @brief @c assign_to overloading for source and target been @c boost::optional.
   //!
   //! @Effects As if <c>to = boost::conversion::convert_to<optional<Target> >(from)</c>.
   //! @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&
- )
+ , 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:15:31 EDT (Tue, 31 May 2011)
@@ -21,46 +21,66 @@
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/assign_to.hpp>
 #include <boost/config.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/utility/enable_if.hpp>
 
 namespace boost {
 
     #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING && ! defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
     namespace conversion { namespace overload_workaround {
- template < class T, class U>
- struct convert_to< rational<T>, rational<U> > {
- inline static rational<T> apply(rational<U> const & from)
- {
- return rational<T>(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
- }
- };
- template < class T, class U>
- struct assign_to< rational<T>, rational<U> > {
- inline static rational<T>& apply(rational<T>& to, const rational<U>& from)
- {
- to.assign(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
- return to;
- }
- };
+ template < class T, class U>
+ struct convert_to< rational<T>, rational<U> > {
+ inline static rational<T> apply(rational<U> const & from)
+ {
+ return rational<T>(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
+ }
+ };
+ template < class T, class U>
+ struct assign_to< rational<T>, rational<U> > {
+ inline static rational<T>& apply(rational<T>& to, const rational<U>& from)
+ {
+ to.assign(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
+ return to;
+ }
+ };
 
     }}
     #else
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ namespace conversion {
+ namespace detail {
+ template <typename T>
+ struct is_rational : mpl::false_ {};
+ template <typename T>
+ struct is_rational< ::boost::rational<T> > : mpl::true_ {};
+
+ }
+ }
+#endif
     //! @brief @c convert_to overloading for source and target been @c boost::rational.
     //!
     //! @Returns the target rational having as numerator and denominator the conversion from the numerator and denominator of the source rational.
     template < class T, class U>
- inline rational<T> convert_to(rational<U> const & from
- , conversion::dummy::type_tag<rational<T> > const&)
+ inline
+ typename enable_if<typename conversion::detail::is_rational<T>::type,T>::type
+ convert_to(rational<U> const & from
+ , conversion::dummy::type_tag<T> const&p=conversion::dummy::type_tag<T>()
+ )
     {
- return rational<T>(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
+ (void)p; // warning removal
+ return T(boost::conversion::convert_to<typename T::int_type>(from.numerator()),
+ boost::conversion::convert_to<typename T::int_type>(from.denominator())
+ );
     }
 
     template < class T, class U>
     inline rational<T>& assign_to(rational<T>& to, const rational<U>& from
- , conversion::dummy::type_tag<rational<T> > const&
- )
+ , conversion::dummy::type_tag<rational<T> > const& p=conversion::dummy::type_tag<rational<T> >()
+ )
     {
- to.assign(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
- return to;
+ (void)p; // warning removal
+ to.assign(boost::conversion::convert_to<T>(from.numerator()), boost::conversion::convert_to<T>(from.denominator()));
+ return to;
     }
     #endif
 

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:15:31 EDT (Tue, 31 May 2011)
@@ -37,28 +37,43 @@
   namespace conversion {
     namespace dummy {
       //! base tag used to overload a function returning T.
+
+ //! @tparam T The wrapped type.
       template <typename T>
       struct base_tag {
+ //! The nested type @c type names the template parameter.
+
         typedef T type;
       };
       //! tag used to overload a function returning T that takes precedence respect to &c base_tag<T>.
       //!
+ //! @tparam T The wrapped type.
       //! Users overloading the @c convert_to function must use this tag.
       template <typename T>
       struct type_tag : public base_tag<T> {
+ //! The nested type @c type names the template parameter.
         typedef T type;
       };
     }
 
     //! meta-function to state if the parameter is a place_holder
     //!
- //! The nested type @c type is a mpl boolean which default to @c mpl::false_. Specific specialization would make this meta-function to be @c mpl::true_.
+ //! @tparam T The type to check for.
+ //! @tparam Enable A dummy parameter that can be used for SFINAE.
+
+ //! The nested type @c type is a mpl boolean which default to @c mpl::false_.
+ //! Specific specialization would make this meta-function to be @c mpl::true_.
     template <typename T, typename Enabled=void>
     struct enable_functor : mpl::false_ {};
 
     namespace overload_workaround {
       //! struct used when overloading of @c convert_to function can not be applied.
- template < typename To, typename From >
+
+ //! @tparam To target type of the conversion.
+ //! @tparam From source type of the conversion.
+ //! @tparam Enable A dummy parameter that can be used for SFINAE.
+
+ template < typename To, typename From, class Enable = void >
       struct convert_to {
         //! @Effects Converts the @c from parameter to an instance of the @c To type, using by default the conversion operator or copy constructor.
         //! @Throws Whatever the underlying conversion @c To operator of the @c From class or the copy constructor of the @c To class throws.
@@ -94,11 +109,19 @@
 
     //! @brief Extrinsic conversion function.
     //!
+ //! @tparam Target target type of the conversion.
+ //! @tparam Source source type of the conversion.
+ //!
+ //! @Params
+ //! @Param{source,source of the conversion}
+ //! @Param{p,a dummy parameter used to allow overloading on the Target type}
+ //!
     //! @Effects Converts the @c from parameter to an instance of the @c To type, using by default the conversion operator or copy constructor.
     //! @Throws Whatever the underlying conversion @c To operator of the @c From class or the copy constructor 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
+ //! 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>
     //!
     //! This function doesn't participate on overload resolution when @c conversion::enable_functor<Source>::type.
     template <typename Target, typename Source>

Modified: sandbox/conversion/boost/conversion/fp/convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/fp/convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/fp/convert_to.hpp 2011-05-31 03:15:31 EDT (Tue, 31 May 2011)
@@ -79,6 +79,30 @@
 
     //! @brief Lazily convert to a type @Target from an arbitrary argument.
     //!
+ //! @Returns A unary functor that will call to the convert_to function on its parameter.
+ //! @Throws Whatever the underlying conversion @c To operator of the @c From class or the copy constructor of the @c To class throws.
+ //! @Example
+ //! @code
+ //! boost::conversion::make_converter_to<int>(_1)(v);
+ //! @endcode
+ //! Creates a functor that when applied to the parameter v, converts it to an @c int.
+ template <typename T, typename U>
+ inline
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ typename expression::convert_to<boost::phoenix::detail::target<T>, U>::type const
+#else
+ unspecified_converter_type
+#endif
+ make_converter_to(U const& u)
+ {
+ return
+ expression::
+ convert_to<boost::phoenix::detail::target<T>, U>::
+ make(boost::phoenix::detail::target<T>(), u);
+ }
+
+ //! @brief Lazily convert to a type @Target from an arbitrary argument.
+ //!
     //! This overload of @convert_to is taken in account when the parameter @c Source is a place_holder.
     //!
     //! @Returns A unary functor that will call to the convert_to function on its parameter.
@@ -95,14 +119,11 @@
       typename expression::convert_to<boost::phoenix::detail::target<T>, U>::type const
>::type
 #else
- typename expression::convert_to<boost::phoenix::detail::target<T>, U>::type const
+ unspecified_converter_type
 #endif
     convert_to(U const& u)
     {
- return
- expression::
- convert_to<boost::phoenix::detail::target<T>, U>::
- make(boost::phoenix::detail::target<T>(), u);
+ return make_converter_to<T>(u);
     }
   }
 }

Modified: sandbox/conversion/boost/conversion/try_assign_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/try_assign_to.hpp (original)
+++ sandbox/conversion/boost/conversion/try_assign_to.hpp 2011-05-31 03:15:31 EDT (Tue, 31 May 2011)
@@ -51,7 +51,7 @@
           To rollback = to;
           try
           {
- to = from;
+ boost::conversion::assign_to<To>(to , from);
             return true;
           }
           catch (...)

Modified: sandbox/conversion/boost/conversion/try_convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/try_convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/try_convert_to.hpp 2011-05-31 03:15:31 EDT (Tue, 31 May 2011)
@@ -35,11 +35,33 @@
 #define BOOST_CONVERSION_TRY_CONVERT_TO_HPP
 
 #include <boost/conversion/convert_to.hpp>
-#include <boost/optional.hpp>
+#include <boost/conversion/boost/optional.hpp>
 
 namespace boost {
   namespace conversion {
     namespace overload_workaround {
+ //! @brief @c convert_to specialization to try to convert the source to @c Target::value_type when @c Target is optional.
+ //!
+ //! We can see this specialization as a try_convert_to function.
+ template < class Target, class Source>
+ struct convert_to< Target, Source, typename enable_if<typename conversion::detail::is_optional<Target>::type>::type >
+ {
+ //! @Returns If the source is convertible to the target @c value_type
+ //! @c Target initialized to the result of the conversion.
+ //! Uninitialized @c Target otherwise.
+ inline static Target apply(Source const & from)
+ {
+ try
+ {
+ return Target(boost::conversion::convert_to<typename Target::value_type>(from));
+ }
+ catch (...)
+ {
+ return Target();
+ }
+ }
+ };
+
       //! <c>struct try_convert_to</c> used when overloading can not be applied.
       //! This struct can be specialized by the user.
       template < typename To, typename From >


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