diff --git a/include/boost/functional/overloaded_function.hpp b/include/boost/functional/overloaded_function.hpp index a918e11..e8ee9f3 100644 --- a/include/boost/functional/overloaded_function.hpp +++ b/include/boost/functional/overloaded_function.hpp @@ -14,6 +14,7 @@ # include # include # include +# include # include # include # include @@ -81,8 +82,6 @@ BOOST_FUNCTIONAL_f_type(z, n, ~) \ >::type -namespace boost { - // Iterate within namespace. # define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PP_SUB( /*at least 2 func to overload 2, 3, ...*/\ @@ -90,8 +89,6 @@ namespace boost { "boost/functional/overloaded_function.hpp")) # include BOOST_PP_ITERATE() // Iterate over function arity. -} // namespace - #undef BOOST_FUNCTIONAL_f_type #undef BOOST_FUNCTIONAL_f_arg #undef BOOST_FUNCTIONAL_f_tparam @@ -119,6 +116,11 @@ namespace boost { BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \ 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< BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt, BOOST_FUNCTIONAL_is_tspec) @@ -165,6 +167,12 @@ overloaded_function< >(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_is_tspec #endif // iteration diff --git a/overloaded_function/test/Jamfile.v2 b/overloaded_function/test/Jamfile.v2 index 70d65f9..6b4c0b0 100644 --- a/overloaded_function/test/Jamfile.v2 +++ b/overloaded_function/test/Jamfile.v2 @@ -7,8 +7,6 @@ import testing ; -project : requirements /boost//unit_test_framework ; - run functor.cpp ; run make_decl.cpp ; run make_call.cpp ; diff --git a/overloaded_function/test/functor.cpp b/overloaded_function/test/functor.cpp index 6f028a3..86827fc 100644 --- a/overloaded_function/test/functor.cpp +++ b/overloaded_function/test/functor.cpp @@ -7,14 +7,13 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestFunctor -#include +#include -BOOST_AUTO_TEST_CASE(test_functor) { +int main() { //[identity_calls - BOOST_CHECK(identity_s("abc") == "abc"); - BOOST_CHECK(identity_i(123) == 123); - BOOST_CHECK(identity_d(1.23) == 1.23); + BOOST_TEST(identity_s("abc") == "abc"); + BOOST_TEST(identity_i(123) == 123); + BOOST_TEST(identity_d(1.23) == 1.23); //] //[identity_functor @@ -25,9 +24,11 @@ BOOST_AUTO_TEST_CASE(test_functor) { > identity(identity_s, identity_i, identity_d); // All calls via single `identity` function. - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); //] + + return boost::report_errors(); } diff --git a/overloaded_function/test/identity.hpp b/overloaded_function/test/identity.hpp index 6602152..db7905a 100644 --- a/overloaded_function/test/identity.hpp +++ b/overloaded_function/test/identity.hpp @@ -19,6 +19,12 @@ int (&identity_i)(int) = identity_i_impl; // Function reference. double identity_d_impl(double x) { return x; } boost::function identity_d = identity_d_impl; // Functor. + +// For type-of emulation on compilers without native type-of. +#include +#include +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Use `functionN`. //] #endif // #include guard diff --git a/overloaded_function/test/make_call.cpp b/overloaded_function/test/make_call.cpp index 651fb10..e2abdde 100644 --- a/overloaded_function/test/make_call.cpp +++ b/overloaded_function/test/make_call.cpp @@ -7,21 +7,21 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestMakeCall -#include +#include //[identity_make_checks template void check(F identity) { - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); } //] -BOOST_AUTO_TEST_CASE(test_identity) { +int main() { //[identity_make_call check(boost::make_overloaded_function(identity_s, identity_i, identity_d)); //] + return boost::report_errors(); } diff --git a/overloaded_function/test/make_decl.cpp b/overloaded_function/test/make_decl.cpp index 4348e9c..919b77b 100644 --- a/overloaded_function/test/make_decl.cpp +++ b/overloaded_function/test/make_decl.cpp @@ -7,17 +7,17 @@ #include "identity.hpp" #include -#define BOOST_TEST_MODULE TestMakeDecl -#include +#include -BOOST_AUTO_TEST_CASE(test_make_decl) { +int main() { //[identity_make BOOST_AUTO(identity, boost::make_overloaded_function( identity_s, identity_i, identity_d)); - BOOST_CHECK(identity("abc") == "abc"); - BOOST_CHECK(identity(123) == 123); - BOOST_CHECK(identity(1.23) == 1.23); + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); //] + return boost::report_errors(); }