From 5a10daef4df5d777a8cc4c5bf4dabaf642d19085 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 15 Oct 2002 10:51:34 +0000 Subject: [PATCH] bind(type(), f, ...) alternative syntax support. [SVN r15928] --- bind_test.cpp | 20 ++++++++++ include/boost/bind.hpp | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/bind_test.cpp b/bind_test.cpp index 6777dfe..07c291e 100644 --- a/bind_test.cpp +++ b/bind_test.cpp @@ -190,12 +190,31 @@ void function_object_test() #if !defined(__MWERKS__) || (__MWERKS__ > 0x2406) // Fails for this version of the compiler. + global_result = 0; bind(Y(), i, _1, 9, 4)(k); BOOST_TEST( global_result == 4938 ); #endif } +void function_object_test2() +{ + using namespace boost; + + short i(6); + + int const k = 3; + + BOOST_TEST( bind(type(), Y(), ref(i))() == 7 ); + BOOST_TEST( bind(type(), Y(), ref(i))() == 8 ); + BOOST_TEST( bind(type(), Y(), i, _1)(k) == 38 ); + BOOST_TEST( bind(type(), Y(), i, _1, 9)(k) == 938 ); + + global_result = 0; + bind(type(), Y(), i, _1, 9, 4)(k); + BOOST_TEST( global_result == 4938 ); +} + // #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) @@ -487,6 +506,7 @@ int main() { function_test(); function_object_test(); + function_object_test2(); #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) adaptable_function_object_test(); diff --git a/include/boost/bind.hpp b/include/boost/bind.hpp index ba94197..3aeb5f8 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include // Borland-specific bug, visit_each() silently fails to produce code @@ -1247,6 +1248,88 @@ template(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); } +// generic function objects, alternative syntax + +template + _bi::bind_t + BOOST_BIND(boost::type, F f) +{ + typedef _bi::list0 list_type; + return _bi::bind_t (f, list_type()); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1) +{ + typedef typename _bi::list_av_1::type list_type; + return _bi::bind_t (f, list_type(a1)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2) +{ + typedef typename _bi::list_av_2::type list_type; + return _bi::bind_t (f, list_type(a1, a2)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3) +{ + typedef typename _bi::list_av_3::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4) +{ + typedef typename _bi::list_av_4::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) +{ + typedef typename _bi::list_av_5::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) +{ + typedef typename _bi::list_av_6::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) +{ + typedef typename _bi::list_av_7::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) +{ + typedef typename _bi::list_av_8::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8)); +} + +template + _bi::bind_t::type> + BOOST_BIND(boost::type, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) +{ + typedef typename _bi::list_av_9::type list_type; + return _bi::bind_t(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9)); +} + #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) // adaptable function objects