forked from boostorg/functional
Registering all types so Boost.Functional/OverloadedFunction works in type-of emulation mode (and not just native).
[SVN r77709]
This commit is contained in:
@@ -7,8 +7,6 @@
|
||||
|
||||
import testing ;
|
||||
|
||||
project : requirements <library>/boost//unit_test_framework ;
|
||||
|
||||
run functor.cpp ;
|
||||
run make_decl.cpp ;
|
||||
run make_call.cpp ;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user