From 807bbfd434863685ee6134d813f3dbdfd8f4e514 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 7 Mar 2004 16:39:15 +0000 Subject: [PATCH] Next round of MSVC 6/7 fixes. [SVN r22453] --- include/boost/bind.hpp | 520 ++++++++------------------- include/boost/bind/bind_template.hpp | 46 +-- test/bind_stateful_test.cpp | 87 +++-- 3 files changed, 241 insertions(+), 412 deletions(-) diff --git a/include/boost/bind.hpp b/include/boost/bind.hpp index f3fb5ee..8683675 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -10,7 +10,7 @@ // // bind.hpp - binds function objects to arguments // -// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd. // Copyright (c) 2001 David Abrahams // // Permission to copy, use, modify, sell and distribute this software @@ -26,6 +26,7 @@ #include #include #include +#include // Borland-specific bug, visit_each() silently fails to produce code @@ -112,43 +113,23 @@ template class type {}; // unwrap -template inline F & unwrap(F & f, long) +template inline F & unwrap(F * f, long) { - return f; + return *f; } -template inline F * unwrap(F * f, int) +template inline F & unwrap(reference_wrapper * f, int) { - return f; + return f->get(); } -template inline F & unwrap(reference_wrapper & f, int) +template inline F & unwrap(reference_wrapper const * f, int) { - return f; -} - -template inline F & unwrap(reference_wrapper const & f, int) -{ - return f; + return f->get(); } // listN -#ifdef BOOST_NO_VOID_RETURNS - -template struct evaluator0; -template struct evaluator1; -template struct evaluator2; -template struct evaluator3; -template struct evaluator4; -template struct evaluator5; -template struct evaluator6; -template struct evaluator7; -template struct evaluator8; -template struct evaluator9; - -#endif - class list0 { public: @@ -165,14 +146,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A &) + template R operator()(type, F & f, A &, long) { - return unwrap(f, 0)(); + return unwrap(&f, 0)(); } - template R operator()(type, F const & f, A &) const + template R operator()(type, F const & f, A &, long) const { - return unwrap(f, 0)(); + return unwrap(&f, 0)(); + } + + template void operator()(type, F & f, A &, int) + { + unwrap(&f, 0)(); + } + + template void operator()(type, F const & f, A &, int) const + { + unwrap(&f, 0)(); } template void accept(V &) const @@ -183,16 +174,6 @@ public: { return true; } - -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator0 type; - }; - -#endif - }; template class list1 @@ -215,14 +196,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_]); + return unwrap(&f, 0)(a[a1_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_]); + return unwrap(&f, 0)(a[a1_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_]); } template void accept(V & v) const @@ -235,19 +226,8 @@ public: return ref_compare(a1_, rhs.a1_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator1 type; - }; - -#else - private: -#endif - A1 a1_; }; @@ -273,14 +253,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_]); + return unwrap(&f, 0)(a[a1_], a[a2_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_]); + return unwrap(&f, 0)(a[a1_], a[a2_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_]); } template void accept(V & v) const @@ -294,19 +284,8 @@ public: return ref_compare(a1_, rhs.a1_, 0) && ref_compare(a2_, rhs.a2_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator2 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; }; @@ -335,14 +314,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_]); } template void accept(V & v) const @@ -357,19 +346,8 @@ public: return ref_compare(a1_, rhs.a1_, 0) && ref_compare(a2_, rhs.a2_, 0) && ref_compare(a3_, rhs.a3_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator3 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -401,14 +379,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_]); } template void accept(V & v) const @@ -426,19 +414,8 @@ public: ref_compare(a4_, rhs.a4_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator4 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -473,14 +450,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); } template void accept(V & v) const @@ -499,19 +486,8 @@ public: ref_compare(a4_, rhs.a4_, 0) && ref_compare(a5_, rhs.a5_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator5 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -549,14 +525,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); } template void accept(V & v) const @@ -576,19 +562,8 @@ public: ref_compare(a4_, rhs.a4_, 0) && ref_compare(a5_, rhs.a5_, 0) && ref_compare(a6_, rhs.a6_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator6 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -629,14 +604,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); } template void accept(V & v) const @@ -658,19 +643,8 @@ public: ref_compare(a7_, rhs.a7_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator7 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -714,14 +688,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); } template void accept(V & v) const @@ -744,19 +728,8 @@ public: ref_compare(a7_, rhs.a7_, 0) && ref_compare(a8_, rhs.a8_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator8 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -803,14 +776,24 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F & f, A & a) + template R operator()(type, F & f, A & a, long) { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); } - template R operator()(type, F const & f, A & a) const + template R operator()(type, F const & f, A & a, long) const { - return unwrap(f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); + return unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); + } + + template void operator()(type, F & f, A & a, int) + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); + } + + template void operator()(type, F const & f, A & a, int) const + { + unwrap(&f, 0)(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); } template void accept(V & v) const @@ -834,19 +817,8 @@ public: ref_compare(a7_, rhs.a7_, 0) && ref_compare(a8_, rhs.a8_, 0) && ref_compare(a9_, rhs.a9_, 0); } -#ifdef BOOST_NO_VOID_RETURNS - - template struct evaluator - { - typedef evaluator9 type; - }; - -#else - private: -#endif - A1 a1_; A2 a2_; A3 a3_; @@ -858,190 +830,6 @@ private: A9 a9_; }; -#ifdef BOOST_NO_VOID_RETURNS - -template struct evaluator0 -{ - template - static R eval(L &, F & f, A &) - { - return unwrap(f, 0)(); - } -}; - -template <> struct evaluator0 -{ - template - static void eval(L &, F & f, A &) - { - unwrap(f, 0)(); - } -}; - -template struct evaluator1 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_]); - } -}; - -template <> struct evaluator1 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_]); - } -}; - -template struct evaluator2 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_]); - } -}; - -template <> struct evaluator2 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_]); - } -}; - -template struct evaluator3 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_]); - } -}; - -template <> struct evaluator3 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_]); - } -}; - -template struct evaluator4 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]); - } -}; - -template <> struct evaluator4 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]); - } -}; - -template struct evaluator5 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]); - } -}; - -template <> struct evaluator5 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]); - } -}; - -template struct evaluator6 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]); - } -}; - -template <> struct evaluator6 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_]); - } -}; - -template struct evaluator7 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]); - } -}; - -template <> struct evaluator7 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_]); - } -}; - -template struct evaluator8 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]); - } -}; - -template <> struct evaluator8 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_]); - } -}; - -template struct evaluator9 -{ - template - static R eval(L & l, F & f, A & a) - { - return unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]); - } -}; - -template <> struct evaluator9 -{ - template - static void eval(L & l, F & f, A & a) - { - unwrap(f, 0)(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_], a[l.a6_], a[l.a7_], a[l.a8_], a[l.a9_]); - } -}; - -#endif - // bind_t #ifndef BOOST_NO_VOID_RETURNS @@ -1054,9 +842,9 @@ public: bind_t(F f, L const & l): f_(f), l_(l) {} -#define BOOST_BIND_EVALUATE return l_(type(), f_, a) +#define BOOST_BIND_RETURN return #include -#undef BOOST_BIND_EVALUATE +#undef BOOST_BIND_RETURN }; @@ -1073,9 +861,9 @@ public: implementation(F f, L const & l): f_(f), l_(l) {} -#define BOOST_BIND_EVALUATE return L::BOOST_NESTED_TEMPLATE evaluator::type::eval(l_, f_, a); +#define BOOST_BIND_RETURN return #include -#undef BOOST_BIND_EVALUATE +#undef BOOST_BIND_RETURN }; @@ -1096,9 +884,9 @@ public: implementation(F f, L const & l): f_(f), l_(l) {} -#define BOOST_BIND_EVALUATE L::BOOST_NESTED_TEMPLATE evaluator::type::eval(l_, f_, a); +#define BOOST_BIND_RETURN #include -#undef BOOST_BIND_EVALUATE +#undef BOOST_BIND_RETURN }; diff --git a/include/boost/bind/bind_template.hpp b/include/boost/bind/bind_template.hpp index 9ab88c9..a509c68 100644 --- a/include/boost/bind/bind_template.hpp +++ b/include/boost/bind/bind_template.hpp @@ -3,7 +3,7 @@ // // Do not include this header directly. // -// Copyright (c) 2001 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd. // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. @@ -18,131 +18,131 @@ result_type operator()() { list0 a; - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } result_type operator()() const { list0 a; - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1) { list1 a(a1); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1) const { list1 a(a1); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2) { list2 a(a1, a2); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2) const { list2 a(a1, a2); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3) { list3 a(a1, a2, a3); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3) const { list3 a(a1, a2, a3); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) { list4 a(a1, a2, a3, a4); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const { list4 a(a1, a2, a3, a4); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) { list5 a(a1, a2, a3, a4, a5); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const { list5 a(a1, a2, a3, a4, a5); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) { list6 a(a1, a2, a3, a4, a5, a6); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const { list6 a(a1, a2, a3, a4, a5, a6); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) { list7 a(a1, a2, a3, a4, a5, a6, a7); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const { list7 a(a1, a2, a3, a4, a5, a6, a7); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) { list8 a(a1, a2, a3, a4, a5, a6, a7, a8); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const { list8 a(a1, a2, a3, a4, a5, a6, a7, a8); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) { list9 a(a1, a2, a3, a4, a5, a6, a7, a8, a9); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const { list9 a(a1, a2, a3, a4, a5, a6, a7, a8, a9); - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type eval(A & a) { - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template result_type eval(A & a) const { - BOOST_BIND_EVALUATE; + BOOST_BIND_RETURN l_(type(), f_, a, 0); } template void accept(V & v) const diff --git a/test/bind_stateful_test.cpp b/test/bind_stateful_test.cpp index 9604b9a..a2b4423 100644 --- a/test/bind_stateful_test.cpp +++ b/test/bind_stateful_test.cpp @@ -44,6 +44,11 @@ public: { } + int state() const + { + return state_; + } + int operator()() { return state_ += 17041; @@ -140,38 +145,74 @@ int f8(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int return state_ += x1+x2+x3+x4+x5+x6+x7+x8; } -template void test(F f, int r) +template void test(F f, int a, int b) { - BOOST_TEST( f() == r ); - BOOST_TEST( f() == 2*r ); - BOOST_TEST( f() == 3*r ); + BOOST_TEST( f() == a + b ); + BOOST_TEST( f() == a + 2*b ); + BOOST_TEST( f() == a + 3*b ); } void stateful_function_object_test() { - test( boost::bind( X() ), 17041 ); - test( boost::bind( X(), 1 ), 1 ); - test( boost::bind( X(), 1, 2 ), 1+2 ); - test( boost::bind( X(), 1, 2, 3 ), 1+2+3 ); - test( boost::bind( X(), 1, 2, 3, 4 ), 1+2+3+4 ); - test( boost::bind( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 ); - test( boost::bind( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 ); - test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 ); - test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 ); - test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 ); + test( boost::bind( X() ), 0, 17041 ); + test( boost::bind( X(), 1 ), 0, 1 ); + test( boost::bind( X(), 1, 2 ), 0, 1+2 ); + test( boost::bind( X(), 1, 2, 3 ), 0, 1+2+3 ); + test( boost::bind( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 ); + test( boost::bind( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 ); + + X x; + + int n = x.state(); + + test( boost::bind( boost::ref(x) ), n, 17041 ); + n += 3*17041; + + test( boost::bind( boost::ref(x), 1 ), n, 1 ); + n += 3*1; + + test( boost::bind( boost::ref(x), 1, 2 ), n, 1+2 ); + n += 3*(1+2); + + test( boost::bind( boost::ref(x), 1, 2, 3 ), n, 1+2+3 ); + n += 3*(1+2+3); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4 ), n, 1+2+3+4 ); + n += 3*(1+2+3+4); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4, 5 ), n, 1+2+3+4+5 ); + n += 3*(1+2+3+4+5); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4, 5, 6 ), n, 1+2+3+4+5+6 ); + n += 3*(1+2+3+4+5+6); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4, 5, 6, 7 ), n, 1+2+3+4+5+6+7 ); + n += 3*(1+2+3+4+5+6+7); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8 ), n, 1+2+3+4+5+6+7+8 ); + n += 3*(1+2+3+4+5+6+7+8); + + test( boost::bind( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n, 1+2+3+4+5+6+7+8+9 ); + n += 3*(1+2+3+4+5+6+7+8+9); + + BOOST_TEST( x.state() == n ); } void stateful_function_test() { - test( boost::bind( f0, 0 ), 17041 ); - test( boost::bind( f1, 0, 1 ), 1 ); - test( boost::bind( f2, 0, 1, 2 ), 1+2 ); - test( boost::bind( f3, 0, 1, 2, 3 ), 1+2+3 ); - test( boost::bind( f4, 0, 1, 2, 3, 4 ), 1+2+3+4 ); - test( boost::bind( f5, 0, 1, 2, 3, 4, 5 ), 1+2+3+4+5 ); - test( boost::bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 ); - test( boost::bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 ); - test( boost::bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 ); + test( boost::bind( f0, 0 ), 0, 17041 ); + test( boost::bind( f1, 0, 1 ), 0, 1 ); + test( boost::bind( f2, 0, 1, 2 ), 0, 1+2 ); + test( boost::bind( f3, 0, 1, 2, 3 ), 0, 1+2+3 ); + test( boost::bind( f4, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 ); + test( boost::bind( f5, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 ); + test( boost::bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 ); + test( boost::bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 ); + test( boost::bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 ); } int main()