|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72570 - in sandbox/conversion/boost/conversion: . boost type_traits
From: vicente.botet_at_[hidden]
Date: 2011-06-13 13:20:44
Author: viboes
Date: 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
New Revision: 72570
URL: http://svn.boost.org/trac/boost/changeset/72570
Log:
Conversion: Make a distiction between implicit and explicit converter
Added:
sandbox/conversion/boost/conversion/explicit_convert_to.hpp (contents, props changed)
sandbox/conversion/boost/conversion/type_traits/is_convertible.hpp (contents, props changed)
sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp (contents, props changed)
Text files modified:
sandbox/conversion/boost/conversion/boost/array.hpp | 1 +
sandbox/conversion/boost/conversion/convert_to.hpp | 13 ++++++-------
sandbox/conversion/boost/conversion/include.hpp | 1 +
3 files changed, 8 insertions(+), 7 deletions(-)
Modified: sandbox/conversion/boost/conversion/boost/array.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/boost/array.hpp (original)
+++ sandbox/conversion/boost/conversion/boost/array.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -58,6 +58,7 @@
return to;
}
};
+
/**
* Partial specialization of @c assigner for @c boost::array of the same size
*/
Modified: sandbox/conversion/boost/conversion/convert_to.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/convert_to.hpp (original)
+++ sandbox/conversion/boost/conversion/convert_to.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -45,7 +45,7 @@
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/integral_constant.hpp>
#if defined(BOOST_CONVERSION_ENABLE_CND)
-#include <boost/conversion/type_traits/is_explicitly_convertible.hpp>
+#include <boost/conversion/type_traits/is_convertible.hpp>
#endif
namespace boost {
@@ -82,7 +82,7 @@
*/
template < typename Target, typename Source>
struct default_converter_condition
- : is_explicitly_convertible<Source,Target>
+ : is_convertible<Source,Target>
{};
#endif
@@ -96,12 +96,12 @@
template < typename Target, typename Source, class Enable = void >
struct converter : converter_cp<Target,Source,Enable> {};
- //! Specialization for @c converter when @c is_explicitly_convertible<Source,Target>.
- //! @Requires @c is_explicitly_convertible<Source,Target>
+ //! Specialization for @c converter when @c is_convertible<Source,Target>.
+ //! @Requires @c is_convertible<Source,Target>
template < typename Target, typename Source >
struct converter<Target, Source
#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
- , typename enable_if<is_explicitly_convertible<Source,Target> >::type
+ , typename enable_if<is_convertible<Source,Target> >::type
#endif
> : true_type
#else
@@ -113,8 +113,7 @@
//! @Throws Whatever the underlying conversion @c Target operator of the @c Source class throws.
Target operator()(const Source& val)
{
- return Target((val));
- //return val;
+ return val;
}
};
#if !defined(BOOST_CONVERSION_ENABLE_CND)
Added: sandbox/conversion/boost/conversion/explicit_convert_to.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/explicit_convert_to.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -0,0 +1,173 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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/conversion for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+/**
+ * @file
+ * @brief Defines the free function @c explicit_convert_to and its customization point @c explicit_converter.
+ *
+ * The @c explicit_convert_to function explicit converts the @c from parameter to a @c Target type.
+ *
+ */
+#ifndef BOOST_CONVERSION_EXPLICIT_CONVERT_TO_HPP
+#define BOOST_CONVERSION_EXPLICIT_CONVERT_TO_HPP
+#if defined(BOOST_CONVERSION_DOUBLE_CP)
+/**
+ * A user adapting another type could need to overload the @c explicit_convert_to free function
+ * if the default behavior is not satisfactory.
+ * The user can add the @c explicit_convert_to overloading on any namespace found by ADL from the @c Source or the @c Target.
+ * A trick is used to overload on the return type by adding a dummy parameter having the Target.
+ *
+ * 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::explicit_convert_to struct.
+ *
+ */
+#endif
+
+
+#include <boost/conversion/convert_to.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/integral_constant.hpp>
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+#include <boost/conversion/type_traits/is_explicitly_convertible.hpp>
+#include <boost/conversion/type_traits/is_extrinsic_convertible.hpp>
+#endif
+
+namespace boost {
+ namespace conversion {
+
+#if defined(BOOST_CONVERSION_ENABLE_CND)
+
+ /**
+ * States the default explicit_converter condition used when no constraint is associated to the @c Target and @c Source parameters.
+ */
+ template < typename Target, typename Source>
+ struct default_explicit_converter_condition
+ : is_explicitly_convertible<Source,Target>
+ {};
+#endif
+
+ //! Customization point for @c explicit_convert_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)
+ template < typename Target, typename Source, class Enable = void >
+ struct explicit_converter_cp : false_type {};
+
+ //! Default @c explicit_converter.
+ template < typename Target, typename Source, class Enable = void >
+ struct explicit_converter : explicit_converter_cp<Target,Source,Enable> {};
+
+ //! 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
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ , typename enable_if<is_explicitly_convertible<Source,Target> >::type
+#endif
+ > : true_type
+#else
+ template < typename Target, typename Source, class Enable = void >
+ struct explicit_converter_cp : true_type
+#endif
+ {
+ //! @Effects Converts the @c from parameter to an instance of the @c Target type, using the conversion operator or copy constructor.
+ //! @Throws Whatever the underlying conversion @c Target operator of the @c Source class throws.
+ Target operator()(const Source& val)
+ {
+ return Target((val));
+ }
+ };
+#if defined(BOOST_CONVERSION_ENABLE_CND) || defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ //! 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
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ , typename enable_if_c<
+ is_extrinsic_convertible<Source,Target>::value
+ && !is_explicitly_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.
+ //! @Throws Whatever the underlying conversion @c Target operator of the @c Source class throws.
+ Target operator()(const Source& val)
+ {
+ return convert_to<Target>(val);
+ }
+ };
+#endif
+#if !defined(BOOST_CONVERSION_ENABLE_CND)
+ template < typename Target, typename Source, class Enable = void >
+ struct explicit_converter : explicit_converter_cp<Target,Source,Enable> {};
+#endif
+
+#if defined(BOOST_CONVERSION_DOUBLE_CP)
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ namespace impl_2 {
+
+ //! @brief Default @c explicit_convert_to overload, used when ADL fails.
+ //!
+ //! @Effects Converts the @c from parameter to an instance of the @c Target type, using by default the conversion operator or copy constructor.
+ //! @Throws Whatever the underlying conversion @c Target operator of the @c Source class or the copy constructor of the @c Target class throws.
+ //! Forwards the call to the overload workaround, which can yet be specialized by the user for standard C++ types.
+ template < typename Target, typename Source >
+ Target explicit_convert_to(const Source& from, dummy::type_tag<Target> const&)
+ {
+ return conversion::explicit_converter<Target,Source>()(from);
+ }
+ }
+
+ namespace impl {
+ template <typename Target, typename Source>
+ Target explicit_convert_to_impl(Source const& from)
+ {
+ using namespace boost::conversion::impl_2;
+ //use boost::conversion::impl_2::explicit_convert_to if ADL fails
+ return explicit_convert_to(from, dummy::type_tag<Target>());
+ }
+ }
+#endif
+#endif
+
+ //! @brief Extrinsic conversion function.
+ //! Converts the @c from parameter to an instance of the @c Target type.
+ //! This function can be seen as an emulation of free function overload of the conversion operator.
+ //! @tparam Target target type of the conversion.
+ //! @tparam Source source type of the conversion.
+ //!
+ //! @Params
+ //! @Param{source,source of the conversion}
+ //!
+ //! @Returns The result of @c explicit_converter customization point.
+ //! @Throws Whatever the @c explicit_converter call operator throws.
+ //!
+ //! This function doesn't participate on overload resolution when @c conversion::enable_functor<Source>::type is mpl::true_.
+ template <typename Target, typename Source>
+#if !defined(BOOST_CONVERSION_DOXYGEN_INVOKED)
+ typename disable_if<typename conversion::enable_functor<Source>::type, Target>::type
+#else
+ Target
+#endif
+ explicit_convert_to(Source const& from)
+ {
+#if defined(BOOST_CONVERSION_DOUBLE_CP)
+ return boost::conversion::impl::explicit_convert_to_impl<Target>(from);
+#else
+ return conversion::explicit_converter<Target,Source>()(from);
+#endif
+ }
+ }
+}
+
+#endif
+
Modified: sandbox/conversion/boost/conversion/include.hpp
==============================================================================
--- sandbox/conversion/boost/conversion/include.hpp (original)
+++ sandbox/conversion/boost/conversion/include.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -18,6 +18,7 @@
#define BOOST_CONVERSION_INCLUDE_HPP
#include <boost/conversion/convert_to.hpp>
+#include <boost/conversion/explicit_convert_to.hpp>
#include <boost/conversion/assign_to.hpp>
#include <boost/conversion/convert_to_via.hpp>
#include <boost/conversion/ca_wrapper.hpp>
Added: sandbox/conversion/boost/conversion/type_traits/is_convertible.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/type_traits/is_convertible.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -0,0 +1,63 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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/conversion for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+/**
+ * @file
+ * @brief
+ */
+
+
+#ifndef BOOST_CONVERSION_TT_IS_CONVERTIBLE_HPP
+#define BOOST_CONVERSION_TT_IS_CONVERTIBLE_HPP
+
+#include <boost/type_traits/integral_constant.hpp>
+#include <boost/type_traits/is_convertible.hpp>
+#include <utility>
+#include <boost/array.hpp>
+#include <complex>
+#include <vector>
+#include <boost/fusion/tuple.hpp>
+
+namespace boost
+{
+ template <class A1, class A2, class B1, class B2>
+ struct is_convertible< std::pair<A1,A2>, std::pair<B1,B2> >
+ : integral_constant<bool, is_convertible<A1,B1>::value && is_convertible<A2,B2>::value >
+ {};
+
+#if 0
+ template <class T1, class T2, std::size_t N>
+ struct is_convertible< boost::array<T1,N>, boost::array<T2,N> >
+ : integral_constant<bool, is_convertible<T1,T2>::value >
+ {};
+#endif
+ template < class Target, class Source>
+ struct is_convertible< std::complex<Target>, std::complex<Source> >
+ : integral_constant<bool, is_convertible<Target,Source>::value >
+ {};
+
+ template < class T1, class A1, class T2, class A2>
+ struct is_convertible< std::vector<T1,A1>, std::vector<T2,A2> >
+ : integral_constant<bool, is_convertible<T1,T2>::value >
+ {};
+
+ template <class A1, class A2, class B1, class B2>
+ struct is_convertible< fusion::tuple<A1,A2>, fusion::tuple<B1,B2> >
+ : integral_constant<bool, is_convertible<A1,B1>::value && is_convertible<A2,B2>::value >
+ {};
+
+ template <class A1, class A2, class A3, class B1, class B2, class B3>
+ struct is_convertible< fusion::tuple<A1,A2,A3>, fusion::tuple<B1,B2,B3> >
+ : integral_constant<bool, is_convertible<A1,B1>::value && is_convertible<A2,B2>::value&& is_convertible<A3,B3>::value >
+ {};
+
+}
+
+#endif
+
Added: sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp
==============================================================================
--- (empty file)
+++ sandbox/conversion/boost/conversion/type_traits/is_extrinsic_explicit_convertible.hpp 2011-06-13 13:20:43 EDT (Mon, 13 Jun 2011)
@@ -0,0 +1,41 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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/conversion for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+/**
+ * @file
+ * @brief
+ */
+
+
+#ifndef BOOST_CONVERSION_TT_IS_EXTRINSIC_EXPLICIT_CONVERTIBLE_HPP
+#define BOOST_CONVERSION_TT_IS_EXTRINSIC_CONVERTIBLE_HPP
+
+#include <boost/conversion/explicit_convert_to.hpp>
+#include <boost/fusion/tuple.hpp>
+
+namespace boost {
+
+ template <class Source, class Target>
+ struct is_extrinsic_explicit_convertible : conversion::explicit_converter<Target, Source> {};
+ template <class T>
+ struct is_extrinsic_explicit_convertible<fusion::void_,T> : false_type {};
+ template <>
+ struct is_extrinsic_explicit_convertible<void, void> : true_type {};
+ template <>
+ struct is_extrinsic_explicit_convertible<const void,void> : true_type {};
+ template <>
+ struct is_extrinsic_explicit_convertible<void, const void> : true_type {};
+ template <>
+ struct is_extrinsic_explicit_convertible<const void, const void> : true_type {};
+
+}
+
+
+#endif
+
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