mirror of
https://github.com/boostorg/functional.git
synced 2025-08-01 21:44:28 +02:00
Registering all types so Boost.Functional/OverloadedFunction works in type-of emulation mode (and not just native).
[SVN r77709]
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# include <boost/functional/overloaded_function/detail/base.hpp>
|
# include <boost/functional/overloaded_function/detail/base.hpp>
|
||||||
# include <boost/functional/overloaded_function/detail/function_type.hpp>
|
# include <boost/functional/overloaded_function/detail/function_type.hpp>
|
||||||
# include <boost/functional/overloaded_function/config.hpp>
|
# include <boost/functional/overloaded_function/config.hpp>
|
||||||
|
# include <boost/typeof/typeof.hpp>
|
||||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||||
# include <boost/preprocessor/repetition/enum.hpp>
|
# include <boost/preprocessor/repetition/enum.hpp>
|
||||||
# include <boost/preprocessor/repetition/repeat.hpp>
|
# include <boost/preprocessor/repetition/repeat.hpp>
|
||||||
@@ -81,8 +82,6 @@
|
|||||||
BOOST_FUNCTIONAL_f_type(z, n, ~) \
|
BOOST_FUNCTIONAL_f_type(z, n, ~) \
|
||||||
>::type
|
>::type
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
// Iterate within namespace.
|
// Iterate within namespace.
|
||||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||||
(3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\
|
(3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\
|
||||||
@@ -90,8 +89,6 @@ namespace boost {
|
|||||||
"boost/functional/overloaded_function.hpp"))
|
"boost/functional/overloaded_function.hpp"))
|
||||||
# include BOOST_PP_ITERATE() // Iterate over function arity.
|
# include BOOST_PP_ITERATE() // Iterate over function arity.
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#undef BOOST_FUNCTIONAL_f_type
|
#undef BOOST_FUNCTIONAL_f_type
|
||||||
#undef BOOST_FUNCTIONAL_f_arg
|
#undef BOOST_FUNCTIONAL_f_arg
|
||||||
#undef BOOST_FUNCTIONAL_f_tparam
|
#undef BOOST_FUNCTIONAL_f_tparam
|
||||||
@@ -119,6 +116,11 @@ namespace boost {
|
|||||||
BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
|
BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
|
||||||
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX)
|
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX)
|
||||||
|
|
||||||
|
// For type-of emulation: This must be included at this pp iteration level.
|
||||||
|
# include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
template<
|
template<
|
||||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt,
|
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt,
|
||||||
BOOST_FUNCTIONAL_is_tspec)
|
BOOST_FUNCTIONAL_is_tspec)
|
||||||
@@ -165,6 +167,12 @@ overloaded_function<
|
|||||||
>(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~));
|
>(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
// For type-of emulation: Register overloaded function type (for _AUTO, etc).
|
||||||
|
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function,
|
||||||
|
BOOST_FUNCTIONAL_overloads)
|
||||||
|
|
||||||
# undef BOOST_FUNCTIONAL_overloads
|
# undef BOOST_FUNCTIONAL_overloads
|
||||||
# undef BOOST_FUNCTIONAL_is_tspec
|
# undef BOOST_FUNCTIONAL_is_tspec
|
||||||
#endif // iteration
|
#endif // iteration
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
import testing ;
|
import testing ;
|
||||||
|
|
||||||
project : requirements <library>/boost//unit_test_framework ;
|
|
||||||
|
|
||||||
run functor.cpp ;
|
run functor.cpp ;
|
||||||
run make_decl.cpp ;
|
run make_decl.cpp ;
|
||||||
run make_call.cpp ;
|
run make_call.cpp ;
|
||||||
|
@@ -7,14 +7,13 @@
|
|||||||
|
|
||||||
#include "identity.hpp"
|
#include "identity.hpp"
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
#define BOOST_TEST_MODULE TestFunctor
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_functor) {
|
int main() {
|
||||||
//[identity_calls
|
//[identity_calls
|
||||||
BOOST_CHECK(identity_s("abc") == "abc");
|
BOOST_TEST(identity_s("abc") == "abc");
|
||||||
BOOST_CHECK(identity_i(123) == 123);
|
BOOST_TEST(identity_i(123) == 123);
|
||||||
BOOST_CHECK(identity_d(1.23) == 1.23);
|
BOOST_TEST(identity_d(1.23) == 1.23);
|
||||||
//]
|
//]
|
||||||
|
|
||||||
//[identity_functor
|
//[identity_functor
|
||||||
@@ -25,9 +24,11 @@ BOOST_AUTO_TEST_CASE(test_functor) {
|
|||||||
> identity(identity_s, identity_i, identity_d);
|
> identity(identity_s, identity_i, identity_d);
|
||||||
|
|
||||||
// All calls via single `identity` function.
|
// All calls via single `identity` function.
|
||||||
BOOST_CHECK(identity("abc") == "abc");
|
BOOST_TEST(identity("abc") == "abc");
|
||||||
BOOST_CHECK(identity(123) == 123);
|
BOOST_TEST(identity(123) == 123);
|
||||||
BOOST_CHECK(identity(1.23) == 1.23);
|
BOOST_TEST(identity(1.23) == 1.23);
|
||||||
//]
|
//]
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,12 @@ int (&identity_i)(int) = identity_i_impl; // Function reference.
|
|||||||
|
|
||||||
double identity_d_impl(double x) { return x; }
|
double identity_d_impl(double x) { return x; }
|
||||||
boost::function<double (double)> identity_d = identity_d_impl; // Functor.
|
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::function1, 2) // Use `functionN`.
|
||||||
//]
|
//]
|
||||||
|
|
||||||
#endif // #include guard
|
#endif // #include guard
|
||||||
|
@@ -7,21 +7,21 @@
|
|||||||
|
|
||||||
#include "identity.hpp"
|
#include "identity.hpp"
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
#define BOOST_TEST_MODULE TestMakeCall
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
//[identity_make_checks
|
//[identity_make_checks
|
||||||
template<typename F>
|
template<typename F>
|
||||||
void check(F identity) {
|
void check(F identity) {
|
||||||
BOOST_CHECK(identity("abc") == "abc");
|
BOOST_TEST(identity("abc") == "abc");
|
||||||
BOOST_CHECK(identity(123) == 123);
|
BOOST_TEST(identity(123) == 123);
|
||||||
BOOST_CHECK(identity(1.23) == 1.23);
|
BOOST_TEST(identity(1.23) == 1.23);
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_identity) {
|
int main() {
|
||||||
//[identity_make_call
|
//[identity_make_call
|
||||||
check(boost::make_overloaded_function(identity_s, identity_i, identity_d));
|
check(boost::make_overloaded_function(identity_s, identity_i, identity_d));
|
||||||
//]
|
//]
|
||||||
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,17 +7,17 @@
|
|||||||
|
|
||||||
#include "identity.hpp"
|
#include "identity.hpp"
|
||||||
#include <boost/functional/overloaded_function.hpp>
|
#include <boost/functional/overloaded_function.hpp>
|
||||||
#define BOOST_TEST_MODULE TestMakeDecl
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_make_decl) {
|
int main() {
|
||||||
//[identity_make
|
//[identity_make
|
||||||
BOOST_AUTO(identity, boost::make_overloaded_function(
|
BOOST_AUTO(identity, boost::make_overloaded_function(
|
||||||
identity_s, identity_i, identity_d));
|
identity_s, identity_i, identity_d));
|
||||||
|
|
||||||
BOOST_CHECK(identity("abc") == "abc");
|
BOOST_TEST(identity("abc") == "abc");
|
||||||
BOOST_CHECK(identity(123) == 123);
|
BOOST_TEST(identity(123) == 123);
|
||||||
BOOST_CHECK(identity(1.23) == 1.23);
|
BOOST_TEST(identity(1.23) == 1.23);
|
||||||
//]
|
//]
|
||||||
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user