Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72946 - sandbox/conversion/boost/conversion
From: vicente.botet_at_[hidden]
Date: 2011-07-06 21:51:34


Author: viboes
Date: 2011-07-06 21:51:33 EDT (Wed, 06 Jul 2011)
New Revision: 72946
URL: http://svn.boost.org/trac/boost/changeset/72946

Log:
conversion: update comments
Text files modified:
   sandbox/conversion/boost/conversion/convert_to_or_fallback.hpp | 43 ++++++++++++++++++++++++++++++++++++---
   sandbox/conversion/boost/conversion/explicit_convert_to.hpp | 2
   sandbox/conversion/boost/conversion/implicit_convert_to.hpp | 2
   sandbox/conversion/boost/conversion/try_convert_to.hpp | 2
   4 files changed, 42 insertions(+), 7 deletions(-)

Modified: sandbox/conversion/boost/conversion/convert_to_or_fallback.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/convert_to_or_fallback.hpp (original)
+++ sandbox/conversion/boost/conversion/convert_to_or_fallback.hpp 2011-07-06 21:51:33 EDT (Wed, 06 Jul 2011)
@@ -40,6 +40,7 @@
 #include <boost/conversion/config.hpp>
 #include <boost/conversion/convert_to.hpp>
 #include <boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/utility/enable_if.hpp>
 
 namespace boost {
@@ -63,7 +64,7 @@
     //! @tparam Fallback type of the fallback value which must be explicitly convertible to @c Target.
     //! @tparam Enable A dummy template parameter that can be used for SFINAE.
     //!
- //! The default implementation relies on the @c converter_or_fallbacker_cp which must be specialized by the user.
+ //! The default implementation relies on the @c converter_or_fallbacker_cp customization point which must be specialized by the user.
     template < typename Target, typename Source, typename Fallback=Target, class Enable = void>
     struct converter_or_fallbacker : converter_or_fallbacker_cp<Target,Source,Fallback,Enable> {};
 
@@ -171,22 +172,56 @@
 #endif
 
     //! @brief Extrinsic conversion function with fallback.
- //! Converts the @c from parameter to an instance of the @c Target type.
+ //! Converts the @c from parameter to a @c Target type. If the conversion fails the fallback value is used to construct a Target @c instance.
     //! @tparam Target target type of the conversion.
     //! @tparam Source source type of the conversion.
     //! @tparam Fallback type of the fallback value which must be explicitly convertible to @c Target.
     //!
     //! @Returns the converted value if the conversion succeeds or the fallback.
     //! @Throws Whatever the conversion from @c Fallback to @c Target can throws when the conversion fails.
- //!
+ //! @Remarks This function doesn't participate in function overload when the @c Fallback is the same as the @c Target.
+ //! @Example
+ //! @code
+ //! std::string s="not an int";
+ //! int t=boost::conversion::convert_to_or_fallback<int>(s,-1);
+ //! @endcode
     template <typename Target, typename Source, typename Fallback>
- Target convert_to_or_fallback(Source const& from, Fallback const& fallback) {
+#if defined(BOOST_CONVERSION_ENABLE_CND) || !defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ typename enable_if_c<
+ ! is_same<Target,Fallback>::value
+ , Target>::type
+#else
+ Target
+#endif
+ convert_to_or_fallback(Source const& from, Fallback const& fallback) {
 #if defined(BOOST_CONVERSION_DOUBLE_CP)
       return conversion::impl::convert_to_or_fallback_impl<Target>(from, fallback);
 #else
       return conversion::converter_or_fallbacker<Target,Source,Fallback>()(from, fallback);
 #endif
     }
+#if defined(BOOST_CONVERSION_ENABLE_CND) || !defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ //! @brief Extrinsic conversion function with fallback.
+ //! Converts the @c from parameter to a @c Target type. If the conversion fails the fallback value is used to construct a Target @c instance.
+ //! @tparam Target target type of the conversion.
+ //! @tparam Source source type of the conversion.
+ //!
+ //! @Returns the converted value if the conversion succeeds or the fallback.
+ //! @Throws Whatever the conversion from @c Target to @c Target can throws when the conversion fails.
+ //! @Example
+ //! @code
+ //! std::string s="not an int";
+ //! int t=boost::conversion::convert_to_or_fallback(s,-1);
+ //! @endcode
+ template <typename Target, typename Source>
+ Target convert_to_or_fallback(Source const& from, Target const& fallback) {
+#if defined(BOOST_CONVERSION_DOUBLE_CP)
+ return conversion::impl::convert_to_or_fallback_impl<Target>(from, fallback);
+#else
+ return conversion::converter_or_fallbacker<Target,Source>()(from, fallback);
+#endif
+ }
+#endif
   }
 }
 

Modified: sandbox/conversion/boost/conversion/explicit_convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/explicit_convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/explicit_convert_to.hpp 2011-07-06 21:51:33 EDT (Wed, 06 Jul 2011)
@@ -251,7 +251,7 @@
     //! @code
     //! Target t;
     //! Source s;
- //! t=boost::conversion::explicit_convert_to(s);
+ //! t=boost::conversion::explicit_convert_to<Target>(s);
     //! @endcode
     template <typename Target, typename Source>
     Target

Modified: sandbox/conversion/boost/conversion/implicit_convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/implicit_convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/implicit_convert_to.hpp 2011-07-06 21:51:33 EDT (Wed, 06 Jul 2011)
@@ -144,7 +144,7 @@
     //! @code
     //! Target t;
     //! Source s;
- //! t=boost::conversion::implicit_convert_to(s);
+ //! t=boost::conversion::implicit_convert_to<Target>(s);
     //! @endcode
     template <typename Target, typename Source>
     Target

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-07-06 21:51:33 EDT (Wed, 06 Jul 2011)
@@ -103,7 +103,7 @@
     //! @code
     //! optional<Target> t;
     //! Source s;
- //! res=boost::conversion::try_convert_to(s);
+ //! res=boost::conversion::try_convert_to<Target>(s);
     //! @endcode
     template <typename Target, typename Source>
     optional<Target> try_convert_to(Source const& 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