// Boost.Function library // Copyright Douglas Gregor 2001-2003. Use, modification and // distribution is subject to 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) // For more information, see http://www.boost.org/libs/function // William Kempf, Jesse Jones and Karl Nelson were all very helpful in the // design of this library. #include #if !BOOST_FUNCTION_ENABLE_CXX03 #ifndef BOOST_FUNCTION_HPP_INCLUDED #define BOOST_FUNCTION_HPP_INCLUDED #include #include #include #include namespace boost { #define BOOST_FUNCTION_TARGET_FIX(x) using std::bad_function_call; template class function: public std::function { public: function() = default; function(function const&) = default; function(function&&) = default; using std::function::function; template function( boost::reference_wrapper rt ): std::function( std::ref( rt.get() ) ) { } function& operator=( function const& r ) = default; function& operator=( function&& r ) = default; template function& operator=( function const& r ) { std::function::operator=( static_cast< std::function const& >( r ) ); return *this; } template function& operator=( function&& r ) { std::function::operator=( static_cast< std::function&& >( r ) ); return *this; } template::value && !std::is_same::value >::type > function& operator=( F f ) { std::function::operator=( std::move( f ) ); return *this; } function& operator=( std::nullptr_t f ) { std::function::operator=( f ); return *this; } template function& operator=( boost::reference_wrapper rt ) { std::function::operator=( std::ref( rt.get() ) ); return *this; } bool empty() const noexcept { return ! *this; } void clear() { *this = nullptr; } template void assign( F f, A ) { this->operator=( std::move( f ) ); } template F * target() noexcept { if( F * p = std::function::template target() ) { return p; } if( std::reference_wrapper * p = std::function::template target< std::reference_wrapper >() ) { return std::addressof( p->get() ); } return nullptr; } template F const * target() const noexcept { if( F const * p = std::function::template target() ) { return p; } if( std::reference_wrapper const * p = std::function::template target< std::reference_wrapper >() ) { return std::addressof( p->get() ); } return nullptr; } template bool contains( F const& f ) const noexcept { if( F const * fp = this->template target() ) { return function_equal( *fp, f ); } else { return false; } } }; template::value && !std::is_same::value>::type> inline bool operator==( function const & g, F f ) { return g.contains( f ); } template::value && !std::is_same::value>::type> inline bool operator!=( function const & g, F f ) { return !g.contains( f ); } template inline bool operator==( function const & g, boost::reference_wrapper rf ) { return g.template target() == std::addressof( rf.get() ); } template inline bool operator!=( function const & g, boost::reference_wrapper rf ) { return g.template target() != std::addressof( rf.get() ); } template::value && !std::is_same::value>::type> inline bool operator==( F f, function const & g ) { return g.contains( f ); } template::value && !std::is_same::value>::type> inline bool operator!=( F f, function const & g ) { return !g.contains( f ); } template inline bool operator==( boost::reference_wrapper rf, function const & g ) { return g.template target() == std::addressof( rf.get() ); } template inline bool operator!=( boost::reference_wrapper rf, function const & g ) { return g.template target() != std::addressof( rf.get() ); } namespace detail { template struct is_similar { BOOST_STATIC_CONSTANT( bool, value = false ); }; template class L, class... T1, class... T2> struct is_similar< L, L > { BOOST_STATIC_CONSTANT( bool, value = true ); }; } // namespace detail #define BOOST_FUNCTION_N_COMMON \ \ using base_type::base_type;\ \ template::value && !detail::is_similar::value >::type > this_type& operator=( F f )\ {\ base_type::operator=( std::move( f ) );\ return *this;\ }\ \ this_type& operator=( std::nullptr_t f )\ {\ base_type::operator=( f );\ return *this;\ }\ \ template this_type& operator=( boost::function const& r )\ {\ base_type::operator=( r );\ return *this;\ }\ \ template this_type& operator=( boost::function&& r )\ {\ base_type::operator=( std::move( r ) );\ return *this;\ } template class function0: public function { private: typedef function0 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function1: public function { private: typedef function1 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function2: public function { private: typedef function2 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function3: public function { private: typedef function3 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function4: public function { private: typedef function4 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function5: public function { private: typedef function5 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function6: public function { private: typedef function6 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function7: public function { private: typedef function7 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function8: public function { private: typedef function8 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function9: public function { private: typedef function9 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function10: public function { private: typedef function10 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; template class function30: public function { private: typedef function30 this_type; typedef function base_type; public: BOOST_FUNCTION_N_COMMON }; } // namespace boost #endif // #ifndef BOOST_FUNCTION_HPP_INCLUDED #else #ifndef BOOST_FUNCTION_MAX_ARGS # define BOOST_FUNCTION_MAX_ARGS 10 #endif // BOOST_FUNCTION_MAX_ARGS #if !defined(BOOST_FUNCTION_MAX_ARGS_DEFINED) || (BOOST_FUNCTION_MAX_ARGS_DEFINED != BOOST_FUNCTION_MAX_ARGS) #if !defined(BOOST_FUNCTION_MAX_ARGS_DEFINED) #define BOOST_FUNCTION_MAX_ARGS_DEFINED 0 #endif #include // unary_function, binary_function #include #include // Include the prologue here so that the use of file-level iteration // in anything that may be included by function_template.hpp doesn't break #include // Older Visual Age C++ version do not handle the file iteration well #if BOOST_WORKAROUND(__IBMCPP__, >= 500) && BOOST_WORKAROUND(__IBMCPP__, < 800) # if BOOST_FUNCTION_MAX_ARGS >= 0 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 1 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 2 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 3 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 4 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 5 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 6 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 7 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 8 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 9 # include # endif # if BOOST_FUNCTION_MAX_ARGS >= 10 # include # endif #else // What is the '3' for? # define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_FUNCTION_MAX_ARGS,)) # include BOOST_PP_ITERATE() # undef BOOST_PP_ITERATION_PARAMS_1 #endif #endif // !defined(BOOST_FUNCTION_MAX_ARGS_DEFINED) || (BOOST_FUNCTION_MAX_ARGS_DEFINED != BOOST_FUNCTION_MAX_ARGS) #endif