Registering all types so Boost.Functional/OverloadedFunction works in type-of emulation mode (and not just native).

[SVN r77709]
This commit is contained in:
Lorenzo Caminiti
2012-04-02 01:08:20 +00:00
parent b2dd5d8ac5
commit 1326990a7e
6 changed files with 40 additions and 27 deletions
-2
View File
@@ -7,8 +7,6 @@
import testing ;
project : requirements <library>/boost//unit_test_framework ;
run functor.cpp ;
run make_decl.cpp ;
run make_call.cpp ;
+10 -9
View File
@@ -7,14 +7,13 @@
#include "identity.hpp"
#include <boost/functional/overloaded_function.hpp>
#define BOOST_TEST_MODULE TestFunctor
#include <boost/test/unit_test.hpp>
#include <boost/detail/lightweight_test.hpp>
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();
}
+6
View File
@@ -19,6 +19,12 @@ 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::function1, 2) // Use `functionN`.
//]
#endif // #include guard
+6 -6
View File
@@ -7,21 +7,21 @@
#include "identity.hpp"
#include <boost/functional/overloaded_function.hpp>
#define BOOST_TEST_MODULE TestMakeCall
#include <boost/test/unit_test.hpp>
#include <boost/detail/lightweight_test.hpp>
//[identity_make_checks
template<typename F>
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();
}
+6 -6
View File
@@ -7,17 +7,17 @@
#include "identity.hpp"
#include <boost/functional/overloaded_function.hpp>
#define BOOST_TEST_MODULE TestMakeDecl
#include <boost/test/unit_test.hpp>
#include <boost/detail/lightweight_test.hpp>
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();
}