mirror of
https://github.com/boostorg/functional.git
synced 2025-07-30 20:47:17 +02:00
Added a specialization to deduced F from boost::function<F> removing the need to register boost::function for type-of emulation (because it required to register boost::functionN instead of boost::function and that was confusing).
[SVN r77891]
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
@ -46,6 +47,15 @@ public:
|
||||
type;
|
||||
};
|
||||
|
||||
// NOTE: When using boost::function in Boost.Typeof emulation mode, the user
|
||||
// has to register boost::functionN instead of boost::function in oder to
|
||||
// do TYPEOF(F::operator()). That is confusing, so boost::function is handled
|
||||
// separately so it does not require any Boost.Typeof registration at all.
|
||||
template<typename F>
|
||||
struct functor_type< boost::function<F> > {
|
||||
typedef F type;
|
||||
};
|
||||
|
||||
// Requires: F is a function type, pointer, reference, or monomorphic functor.
|
||||
// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
|
||||
template<typename F>
|
||||
@ -61,7 +71,7 @@ struct function_type {
|
||||
typename boost::mpl::if_<boost::function_types::
|
||||
is_function_reference<F>,
|
||||
boost::remove_reference<F>
|
||||
, // Requires, it's a functor.
|
||||
, // Else, requires that F is a functor.
|
||||
functor_type<F>
|
||||
>::type
|
||||
>::type
|
||||
|
@ -19,13 +19,6 @@ int (&identity_i)(int) = identity_i_impl; // Function reference.
|
||||
|
||||
double identity_d_impl(double x) { return x; }
|
||||
boost::function<double (double)> identity_d = identity_d_impl; // Functor.
|
||||
|
||||
// For type-of emulation on compilers without native type-of.
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
#include <boost/typeof/std/string.hpp>
|
||||
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
||||
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1)
|
||||
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Also `functionN`.
|
||||
//]
|
||||
|
||||
#endif // #include guard
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "identity.hpp"
|
||||
#include <boost/functional/overloaded_function.hpp>
|
||||
#include <boost/typeof/typeof.hpp> // For `BOOST_AUTO`.
|
||||
#include <boost/typeof/std/string.hpp> // No need to register `boost::function`.
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main() {
|
||||
|
Reference in New Issue
Block a user