|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72768 - in sandbox/conversion/boost/conversion: . fp type_traits
From: vicente.botet_at_[hidden]
Date: 2011-06-26 15:52:44
Author: viboes
Date: 2011-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
New Revision: 72768
URL: http://svn.boost.org/trac/boost/changeset/72768
Log:
Conversion: Adapt config to llvm+Add extractor+update comments for doc
Added:
sandbox/conversion/boost/conversion/extractor.hpp (contents, props changed)
Text files modified:
sandbox/conversion/boost/conversion/assign_to.hpp | 25 +++++++++--
sandbox/conversion/boost/conversion/config.hpp | 6 ++
sandbox/conversion/boost/conversion/convert_to_or_fallback.hpp | 83 +++++++++++++++++++++++++++++++++++++--
sandbox/conversion/boost/conversion/convertible_to.hpp | 6 ++
sandbox/conversion/boost/conversion/explicit_convert_to.hpp | 49 ++++++++++++++---------
sandbox/conversion/boost/conversion/fp/convert_to.hpp | 2
sandbox/conversion/boost/conversion/implicit_convert_to.hpp | 7 ++
sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp | 2
8 files changed, 146 insertions(+), 34 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-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -44,14 +44,19 @@
namespace conversion {
+#if defined(BOOST_CONVERSION_ENABLE_CND) || defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
//! Customization point for @c assign_to.
//! @tparam Target target type of the conversion.
//! @tparam Source source type of the conversion.
//! @tparam Enable A dummy template parameter that can be used for SFINAE.
-
-#if defined(BOOST_CONVERSION_ENABLE_CND) || defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
template < typename Target, typename Source, class Enable = void>
struct assigner_cp : false_type {};
+
+ //! Default customization point for @c assign_to.
+ //! @tparam Target target type of the conversion.
+ //! @tparam Source source type of the conversion.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ //! By default it delegates to the user @c assigner_cp.
template < typename Target, typename Source, class Enable = void>
struct assigner : assigner_cp<Target,Source,Enable> {};
@@ -61,11 +66,15 @@
*/
template < typename Target, typename Source>
struct assigner<Target, Source
- BOOST_CONVERSION_REQUIRES((
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ , requires(CopyAssignable<Target>&&ExtrinsicExplicitConvertible<Source,Target>)
+#else
+ , typename enable_if_c<
is_copy_assignable<Target>::value
&& is_extrinsic_explicit_convertible<Source,Target>::value
&& ! is_assignable<Target,Source>::value
- ))
+ >::type
+#endif
> : true_type
{
//! @Effects Converts the @c from parameter to the @c to parameter, using by default the assignment operator.
@@ -82,7 +91,13 @@
*/
template < typename Target, typename Source>
struct assigner<Target,Source
- BOOST_CONVERSION_REQUIRES((is_assignable<Target, Source>::value))
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ , requires(Assignable<Target,Source>)
+#else
+ , typename enable_if_c<
+ is_assignable<Target, Source>::value
+ >::type
+#endif
> : true_type
{
//! @Effects Assigns the @c from parameter to the @c to parameter.
Modified: sandbox/conversion/boost/conversion/config.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/config.hpp (original)
+++ sandbox/conversion/boost/conversion/config.hpp 2011-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -27,6 +27,9 @@
#if ! defined(BOOST_NO_DECLTYPE)
#if defined _MSC_VER
#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
+ #elif defined __clang__
+ #define BOOST_CONVERSION_ENABLE_CND
+ //#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
#elif defined __GNUC__
#if __GNUC__ < 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )
#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
@@ -39,6 +42,9 @@
#else
#if defined _MSC_VER
#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
+ #elif defined __clang__
+ //#define BOOST_CONVERSION_ENABLE_CND
+ //#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
#elif defined __GNUC__
#if __GNUC__ < 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )
#define BOOST_CONVERSION_NO_IS_ASSIGNABLE
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-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -14,12 +14,14 @@
Defines the free function @c convert_to_or_fallback.
The @c convert_to_or_fallback function 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.
-
+
+ */
+#if defined(BOOST_CONVERSION_DOUBLE_CP)
+/**
The default implementation applies the conversion @c Target operator of the @c Source class or
the copy constructor of the @c Target class. When an exception is thrown the fallback is returned.
Of course if both exist the conversion is ambiguous.
A user adapting another type could need to specialize the @c convert_to_or_fallback free function if the default behavior is not satisfactory.
-
* A user adapting another type could need to overload the @c convert_to_or_fallback free function
* if the default behavior is not satisfactory.
* The user can add the @c convert_to_or_fallback overloading on any namespace found by ADL from the @c Source or the @c Target.
@@ -28,23 +30,91 @@
* But sometimes, as it is the case for the standard classes,
* we can not add new functions on the @c std namespace, so we need a different technique.
* In this case the user can partially specialize the @c boost::conversion::overload_workaround::convert_to_or_fallback struct.
-
*/
+#endif
#ifndef BOOST_CONVERSION_CONVERT_TO_OR_FALLBACK_HPP
#define BOOST_CONVERSION_CONVERT_TO_OR_FALLBACK_HPP
#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
namespace boost {
namespace conversion {
- //! This struct can be specialized by the user.
+#if defined(BOOST_CONVERSION_ENABLE_CND) || !defined(BOOST_NO_SFINAE_EXPR)
+ //! @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.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ template < typename Target, typename Source, typename Fallback=Target, class Enable = void>
+ struct converter_or_fallbacker_cp;
+
+ //! Default @c explicit_converter.
+ //! @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.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ template < typename Target, typename Source, typename Fallback=Target, class Enable = void>
+ struct converter_or_fallbacker : converter_or_fallbacker_cp<Target,Source,Fallback,Enable> {};
+
+ //! Specialization for @c converter_or_fallbacker when
+ //! @c is_extrinsic_explicitly_convertible<Source,Target>
+ //! @c && is_extrinsic_explicitly_convertible<Fallback,Target>.
+ //! @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.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ //! @Requires @c is_extrinsic_explicitly_convertible<Source,Target> && @c is_extrinsic_explicitly_convertible<Fallback,Target>.
+ template < typename Target, typename Source, typename Fallback>
+ struct converter_or_fallbacker<Target, Source, Fallback,
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ requires(ExtrinsicExplicitConvertible<Source,Target> && ExtrinsicExplicitConvertible<Fallback,Target>)
+#else
+ typename enable_if_c<
+ is_extrinsic_explicit_convertible<Source,Target>::value
+ && is_extrinsic_explicit_convertible<Fallback,Target>::value
+ >::type
+#endif
+ > {
+ //!
+ //! @Returns The converted value if the conversion succeeds or the conversion of the fallback.
+ //! @Throws Whatever the conversion from @c Fallback to @c Target can throws when the conversion fails.
+ Target operator()(const Source& val, Fallback const& fallback)
+ {
+ try
+ {
+ return boost::conversion::convert_to<Target>(val);
+ }
+ catch (...)
+ {
+ return boost::conversion::convert_to<Target>(fallback);
+ }
+ }
+ };
+#else
//! @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.
//! @tparam Enable A dummy template parameter that can be used for SFINAE.
template < typename Target, typename Source, typename Fallback=Target, class Enable = void>
- struct converter_or_fallbacker {
+ struct converter_or_fallbacker_cp;
+
+ //! Default @c converter_or_fallbacker.
+ //! @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.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ template < typename Target, typename Source, typename Fallback=Target, class Enable = void>
+ struct converter_or_fallbacker : converter_or_fallbacker_cp<Target,Source,Fallback,Enable> {};
+
+ //! @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.
+ //! @tparam Enable A dummy template parameter that can be used for SFINAE.
+ template < typename Target, typename Source, typename Fallback>
+ struct converter_or_fallbacker<Target, Source, Fallback>
+ {
//!
//! @Requires @c Fallback must be convertible to @c Target and @c ::boost::conversion::convert_to<Target>(from) must be well formed.
//! @Returns The converted value if the conversion succeeds or the fallback.
@@ -57,10 +127,11 @@
}
catch (...)
{
- return Target((fallback));
+ return boost::conversion::convert_to<Target>(fallback);
}
}
};
+#endif
#if defined(BOOST_CONVERSION_DOUBLE_CP)
#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
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-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -43,7 +43,11 @@
#endif
)
: val_(boost::conversion::implicit_convert_to<Target>(source))
- {}
+ {
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+ (void)dummy; // remove warning dummy not used
+#endif
+ }
//! Implicit conversion to @c Target.
//! @Returns @c val_
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-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -62,11 +62,15 @@
//! Specialization for @c explicit_converter when @c is_explicitly_convertible<Source,Target>.
//! @Requires @c is_explicitly_convertible<Source,Target>
template < typename Target, typename Source >
- struct explicit_converter<Target, Source
- BOOST_CONVERSION_REQUIRES((
- is_explicitly_convertible<Source,Target>::value
- && !(detail::is_optional<Target>::value && !detail::is_optional<Source>::value)
- ))
+ struct explicit_converter<Target, Source,
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ requires(ExplicitConvertible<Source,Target>)
+#else
+ typename enable_if_c<
+ is_explicitly_convertible<Source,Target>::value
+ && !(detail::is_optional<Target>::value && !detail::is_optional<Source>::value)
+ >::type
+#endif
> : true_type
{
//! @Effects Converts the @c from parameter to an instance of the @c Target type, using the conversion operator or copy constructor.
@@ -77,14 +81,18 @@
}
};
//! Specialization for @c explicit_converter when @c is_explicitly_convertible<Source,Target>.
- //! @Requires @c is_explicitly_convertible<Source,Target>
+ //! @Requires @c is_extrinsic_convertible<Source,Target>
template < typename Target, typename Source >
- struct explicit_converter<Target, Source
- , typename enable_if_c<
- is_extrinsic_convertible<Source,Target>::value
- && !is_explicitly_convertible<Source,Target>::value
- && !(detail::is_optional<Target>::value && !detail::is_optional<Source>::value)
- >::type
+ struct explicit_converter<Target, Source,
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ requires(ExtrinsicConvertible<Source,Target>)
+#else
+ typename enable_if_c<
+ is_extrinsic_convertible<Source,Target>::value
+ && !is_explicitly_convertible<Source,Target>::value
+ && !(detail::is_optional<Target>::value && !detail::is_optional<Source>::value)
+ >::type
+#endif
> : true_type
{
//! @Effects Converts the @c from parameter to an instance of the @c Target type, using the conversion operator or copy constructor.
@@ -96,16 +104,18 @@
};
//! @brief @c explicit converter specialization to try to convert the source to @c Target::value_type when @c Target is optional.
- //!
+ //! @Requires @c is_extrinsic_explicit_convertible<Source,Target>
//! We can see this specialization as a try_convert_to function.
template < class Target, class Source>
- struct explicit_converter< optional<Target>, Source
- , typename enable_if_c<
-// BOOST_CONVERSION_REQUIRES((
+ struct explicit_converter< optional<Target>, Source,
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ requires(ExtrinsicExplicitConvertible<Source,Target>)
+#else
+ typename enable_if_c<
explicit_converter<Target,Source>::value
&& ! detail::is_optional<Source>::value
-// ))
>::type
+#endif
> : true_type
{
@@ -140,6 +150,7 @@
}
};
+ namespace detail {
template < typename Target, typename Source, bool TargetIsOptional, bool SourceIsOptional>
struct explicit_converter_aux : explicit_converter_cp<Target, Source>
{};
@@ -165,10 +176,10 @@
}
}
};
-
+ }
//! Default @c explicit_converter.
template < typename Target, typename Source, class Enable = void >
- struct explicit_converter : explicit_converter_aux<Target,Source,detail::is_optional<Target>::value, detail::is_optional<Source>::value> {};
+ struct explicit_converter : detail::explicit_converter_aux<Target,Source,detail::is_optional<Target>::value, detail::is_optional<Source>::value> {};
Added: sandbox/conversion/boost/conversion/extractor.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/extractor.hpp 2011-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -0,0 +1,96 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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)
+//
+// See http://www.boost.org/libs/synchro for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+/*!
+ @file
+ @brief
+ Include this file when using conversions from @c std::istream.
+ */
+
+
+#ifndef BOOST_CONVERSION_EXTRACTOR_HPP
+#define BOOST_CONVERSION_EXTRACTOR_HPP
+
+#include <boost/conversion/convert_to.hpp>
+#include <istream>
+
+namespace boost {
+ namespace conversion {
+
+ class extract_t { };
+ const extract_t extract={};
+
+ template <typename T>
+ class extractor {
+ T value_;
+
+ public:
+ extractor(std::istream &is) {
+ is >> value_;
+ }
+
+ T value() const {
+ return value_;
+ };
+ //operator T() const {return value();};
+ };
+
+ template <typename T>
+ class extractor_stream {
+ std::stringstream ios_;
+ T value_;
+
+ public:
+
+ template<typename U>
+ extractor_stream& operator<< (U u) { return (ios_ << u, *this); }
+
+ template<typename U>
+ extractor_stream& operator>> (U u) { return (ios_ >> u, *this); }
+
+
+ extractor<T> operator>> (extract_t const&) {
+ return extractor<T>(ios_);
+ }
+
+
+ //operator T() const {return value();};
+ };
+ template<typename T>
+ struct explicit_converter< T, extractor_stream<T>
+ > : true_type
+ {
+ T operator()(extractor_stream<T> const & from)
+ {
+ //return from.value();
+ return convert_to<T>(const_cast<extractor_stream<T> &>(from)>>extract);
+ }
+ };
+
+ template<typename T>
+ struct explicit_converter< T, extractor<T>
+ > : true_type
+ {
+ T operator()(extractor<T> const & from)
+ {
+ return from.value();
+ }
+ };
+
+ template <typename Target>
+ Target extract2(std::istream &is) {
+ return convert_to<Target>(extractor<Target>(is));
+ }
+
+ }
+}
+
+#endif
+
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-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -43,7 +43,7 @@
//! @c enable_functor meta-function specialization for types @c T satisfying @c phoenix::is_actor<T>.
- //! The nested type @ type is @c mpl::true_.
+ //! The nested type @ type is @c true_type.
template <typename T>
struct enable_functor<T, typename enable_if<phoenix::is_actor<T> >::type> : true_type {};
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-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -61,6 +61,7 @@
//! @tparam Enable A dummy template parameter that can be used for SFINAE.
template < typename Target, typename Source, class Enable = void >
struct converter_cp : false_type {};
+
//! Default customization point for @c implicit_convert_to.
//! @tparam Target target type of the conversion.
//! @tparam Source source type of the conversion.
@@ -73,7 +74,11 @@
//! @Requires @c is_convertible<Source,Target>
template < typename Target, typename Source >
struct converter<Target, Source
- , typename enable_if_c< is_convertible<Source,Target>::value >::type
+#if defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ , requires(Convertible<Source,Target>)
+#else
+ , typename enable_if_c< is_convertible<Source,Target>::value >::type
+#endif
> : true_type
{
//! @Effects Converts the @c from parameter to an instance of the @c Target type, using the conversion operator or copy constructor.
Modified: sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp (original)
+++ sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp 2011-06-26 15:52:42 EDT (Sun, 26 Jun 2011)
@@ -13,7 +13,7 @@
*/
#ifndef BOOST_CONVERSION_TT_IS_EXTRINSIC_EXPLICIT_CONVERTIBLE_HPP
-#define BOOST_CONVERSION_TT_IS_EXTRINSIC_CONVERTIBLE_HPP
+#define BOOST_CONVERSION_TT_IS_EXTRINSIC_EXPLICIT_CONVERTIBLE_HPP
#include <boost/conversion/explicit_convert_to.hpp>
#include <boost/fusion/tuple.hpp>
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