diff --git a/include/boost/function.hpp b/include/boost/function.hpp index ef907e0..3039a0e 100644 --- a/include/boost/function.hpp +++ b/include/boost/function.hpp @@ -10,6 +10,364 @@ // 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 @@ -72,3 +430,5 @@ #endif #endif // !defined(BOOST_FUNCTION_MAX_ARGS_DEFINED) || (BOOST_FUNCTION_MAX_ARGS_DEFINED != BOOST_FUNCTION_MAX_ARGS) + +#endif diff --git a/include/boost/function/detail/config.hpp b/include/boost/function/detail/config.hpp new file mode 100644 index 0000000..0c91df8 --- /dev/null +++ b/include/boost/function/detail/config.hpp @@ -0,0 +1,12 @@ +// Copyright 2019 Peter Dimov +// 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 + +#ifndef BOOST_FUNCTION_DETAIL_CONFIG_HPP_INCLUDED +#define BOOST_FUNCTION_DETAIL_CONFIG_HPP_INCLUDED + +#if !defined(BOOST_FUNCTION_ENABLE_CXX03) +# define BOOST_FUNCTION_ENABLE_CXX03 0 +#endif + +#endif // #ifndef BOOST_FUNCTION_DETAIL_CONFIG_HPP_INCLUDED diff --git a/include/boost/function/detail/maybe_include.hpp b/include/boost/function/detail/maybe_include.hpp index ec88905..878ce46 100644 --- a/include/boost/function/detail/maybe_include.hpp +++ b/include/boost/function/detail/maybe_include.hpp @@ -7,6 +7,10 @@ // For more information, see http://www.boost.org +#include + +#if BOOST_FUNCTION_ENABLE_CXX03 + #if BOOST_FUNCTION_NUM_ARGS == 0 # undef BOOST_FUNCTION_MAX_ARGS_DEFINED # define BOOST_FUNCTION_MAX_ARGS_DEFINED 0 @@ -367,3 +371,5 @@ #else # error Cannot handle Boost.Function objects that accept more than 50 arguments! #endif + +#endif diff --git a/include/boost/function/function_fwd.hpp b/include/boost/function/function_fwd.hpp index e79b504..f36cedd 100644 --- a/include/boost/function/function_fwd.hpp +++ b/include/boost/function/function_fwd.hpp @@ -9,6 +9,7 @@ #ifndef BOOST_FUNCTION_FWD_HPP #define BOOST_FUNCTION_FWD_HPP #include +#include #if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730 && !defined(BOOST_STRICT_CONFIG) // Work around a compiler bug. @@ -24,9 +25,22 @@ namespace boost { namespace python { namespace objects { # define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX #endif +#if !BOOST_FUNCTION_ENABLE_CXX03 +# include +#endif + namespace boost { + +#if BOOST_FUNCTION_ENABLE_CXX03 + class bad_function_call; +#else + + using std::bad_function_call; + +#endif + #if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX) // Preferred syntax template class function;