// Boost.TypeErasure library // // Copyright 2011 Steven Watanabe // // 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) // // $Id$ #ifndef BOOST_TYPE_ERASURE_PARAM_HPP_INCLUDED #define BOOST_TYPE_ERASURE_PARAM_HPP_INCLUDED #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace type_erasure { template class any; template class binding; namespace detail { struct access; } namespace detail { template struct placeholder_conversion : boost::mpl::false_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; template struct placeholder_conversion : boost::mpl::true_ {}; #endif } #ifdef __clang__ #if !__has_feature(cxx_reference_qualified_functions) /** INTERNAL ONLY */ #define BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS #endif #else /** INTERNAL ONLY */ #define BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS #endif /** * \brief A wrapper to help with overload resolution for functions * operating on an @ref any. * * The template arguments are interpreted in * the same way as @ref any. * * A parameter of type @ref param can be initialized * with an @ref any that has the same @c Concept * and base placeholder when there exists a corresponding * standard conversion for the placeholder. * A conversion sequence from @ref any to @ref param is * a better conversion sequence than @ref any to @ref param * iff the corresponding placeholder standard conversion * sequence from P to P1 is a better conversion sequence than * P to P2. * * \note Overloading based on cv-qualifiers and rvalue-ness is * only supported in C++11. In C++03, all conversion sequences * from @ref any to @ref param have the same rank. * * Example: * * \code * void f(param); * void f(param); * void g(param); * void g(param); * * any a; * f(any()); // calls void f(param); * f(a); // calls void f(param); (ambiguous in C++03) * g(any()); // calls void g(param); (ambiguous in C++03) * g(a); // calls void g(param); * \endcode * */ template class param { public: friend struct boost::type_erasure::detail::access; /** INTERNAL ONLY */ typedef void _boost_type_erasure_is_any; /** INTERNAL ONLY */ typedef param _boost_type_erasure_derived_type; template param(any& a #ifndef BOOST_TYPE_ERASURE_DOXYGEN , typename boost::enable_if< ::boost::type_erasure::detail::placeholder_conversion >::type* = 0 #endif ) : _impl(a) {} template param(const any& a #ifndef BOOST_TYPE_ERASURE_DOXYGEN , typename boost::enable_if< ::boost::type_erasure::detail::placeholder_conversion< typename ::boost::add_const::type, T > >::type* = 0 #endif ) : _impl(a) {} #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template param(any&& a #ifndef BOOST_TYPE_ERASURE_DOXYGEN , typename boost::enable_if< ::boost::type_erasure::detail::placeholder_conversion< U&&, T > >::type* = 0 #endif ) : _impl(std::move(a)) {} #endif /** Returns the stored @ref any. */ any get() const { return _impl; } private: any _impl; }; #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS template class param { public: friend struct boost::type_erasure::detail::access; /** INTERNAL ONLY */ typedef void _boost_type_erasure_is_any; /** INTERNAL ONLY */ typedef param _boost_type_erasure_derived_type; param(const ::boost::type_erasure::detail::storage& data, const ::boost::type_erasure::binding& table) : _impl(data, table) {} template param(U& u, typename boost::enable_if< ::boost::is_same > >::type* = 0) : _impl(u) {} any get() const { return _impl; } protected: any _impl; }; template class param : public param { public: friend struct boost::type_erasure::detail::access; /** INTERNAL ONLY */ typedef void _boost_type_erasure_is_any; /** INTERNAL ONLY */ typedef param _boost_type_erasure_derived_type; param(const ::boost::type_erasure::detail::storage& data, const ::boost::type_erasure::binding& table) : param(data, table) {} any get() const { return any( ::boost::type_erasure::detail::access::data(this->_impl), ::boost::type_erasure::detail::access::table(this->_impl)); } }; #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template class param : public param { public: friend struct boost::type_erasure::detail::access; /** INTERNAL ONLY */ typedef void _boost_type_erasure_is_any; /** INTERNAL ONLY */ typedef param _boost_type_erasure_derived_type; param(const ::boost::type_erasure::detail::storage& data, const ::boost::type_erasure::binding& table) : param(data, table) {} any get() const { return any( ::boost::type_erasure::detail::access::data(this->_impl), ::boost::type_erasure::detail::access::table(this->_impl)); } }; #endif #endif /** * \brief Metafunction that creates a @ref param. * * If @c T is a (cv/reference qualifed) placeholder, * returns @ref param<@ref concept_of "concept_of::type", T>, * otherwise, returns T. This metafunction is intended * to be used for function arguments in specializations of * @ref concept_interface. * * \see derived, rebind_any */ template struct as_param { #ifdef BOOST_TYPE_ERASURE_DOXYGEN typedef detail::unspecified type; #else typedef typename ::boost::mpl::if_< ::boost::type_erasure::is_placeholder< typename ::boost::remove_cv< typename ::boost::remove_reference::type>::type>, param::type, T>, T >::type type; #endif }; } } #endif