From 7bdfb4acfcd459d4965283e49383320d23b726e3 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 14 Nov 2001 23:39:32 +0000 Subject: [PATCH] integrated void_returns work [SVN r11702] --- include/boost/bind.hpp | 592 ++++++++++++++++++++++++++++++++++------- 1 file changed, 502 insertions(+), 90 deletions(-) diff --git a/include/boost/bind.hpp b/include/boost/bind.hpp index ea87740..003c41f 100644 --- a/include/boost/bind.hpp +++ b/include/boost/bind.hpp @@ -9,6 +9,7 @@ // bind.hpp - binds function objects to arguments // // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. +// Copyright (c) 2001 David Abrahams // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. @@ -77,6 +78,17 @@ template class type {}; // listN +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; + class list0 { public: @@ -93,11 +105,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & /* a */) const + template + struct evaluator { - return f(); - } - + typedef evaluator0 type; + }; + template void accept(V &) const { } @@ -125,20 +138,21 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_]); - } - + typedef evaluator1 type; + }; + template void accept(V & v) const { v(a1_); } -private: - A1 a1_; +private: + list1 & operator= (list1 const &); }; @@ -161,22 +175,23 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_]); - } - + typedef evaluator2 type; + }; + template void accept(V & v) const { v(a1_); v(a2_); } -private: - A1 a1_; A2 a2_; +private: + list2 & operator= (list2 const &); }; @@ -200,11 +215,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_]); - } - + typedef evaluator3 type; + }; + template void accept(V & v) const { v(a1_); @@ -212,12 +228,12 @@ public: v(a3_); } -private: - A1 a1_; A2 a2_; A3 a3_; +private: + list3 & operator= (list3 const &); }; @@ -242,11 +258,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_]); - } - + typedef evaluator4 type; + }; + template void accept(V & v) const { v(a1_); @@ -255,13 +272,13 @@ public: v(a4_); } -private: - A1 a1_; A2 a2_; A3 a3_; A4 a4_; +private: + list4 & operator= (list4 const &); }; @@ -287,11 +304,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_]); - } - + typedef evaluator5 type; + }; + template void accept(V & v) const { v(a1_); @@ -301,14 +319,14 @@ public: v(a5_); } -private: - A1 a1_; A2 a2_; A3 a3_; A4 a4_; A5 a5_; +private: + list5 & operator= (list5 const &); }; @@ -335,11 +353,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_]); - } - + typedef evaluator6 type; + }; + template void accept(V & v) const { v(a1_); @@ -350,8 +369,6 @@ public: v(a6_); } -private: - A1 a1_; A2 a2_; A3 a3_; @@ -359,6 +376,8 @@ private: A5 a5_; A6 a6_; +private: + list6 & operator= (list6 const &); }; @@ -386,11 +405,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_]); - } - + typedef evaluator7 type; + }; + template void accept(V & v) const { v(a1_); @@ -402,8 +422,6 @@ public: v(a7_); } -private: - A1 a1_; A2 a2_; A3 a3_; @@ -412,6 +430,8 @@ private: A6 a6_; A7 a7_; +private: + list7 & operator= (list7 const &); }; @@ -440,11 +460,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_]); - } - + typedef evaluator8 type; + }; + template void accept(V & v) const { v(a1_); @@ -457,8 +478,6 @@ public: v(a8_); } -private: - A1 a1_; A2 a2_; A3 a3_; @@ -468,6 +487,8 @@ private: A7 a7_; A8 a8_; +private: + list8 & operator= (list8 const &); }; @@ -497,11 +518,12 @@ public: template typename result_traits::type operator[] (bind_t const & b) const { return b.eval(*this); } - template R operator()(type, F f, A & a) const + template + struct evaluator { - return f(a[a1_], a[a2_], a[a3_], a[a4_], a[a5_], a[a6_], a[a7_], a[a8_], a[a9_]); - } - + typedef evaluator9 type; + }; + template void accept(V & v) const { v(a1_); @@ -515,8 +537,6 @@ public: v(a9_); } -private: - A1 a1_; A2 a2_; A3 a3_; @@ -527,147 +547,353 @@ private: A8 a8_; A9 a9_; +private: + list9 & operator= (list9 const &); }; // bind_t -template class bind_t +template struct evaluator0 { -public: + template + static R eval(L const&, F f, A &) + { + return f(); + } +}; +template <> struct evaluator0 +{ + template + static void eval(L const&, F f, A &) + { + f(); + } +}; + +template struct evaluator1 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(a[l.a1_]); + } +}; + +template <> struct evaluator1 +{ + template + static void eval(L const& l, F f, A & a) + { + f(a[l.a1_]); + } +}; + +template struct evaluator2 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(a[l.a1_], a[l.a2_]); + } +}; + +template <> struct evaluator2 +{ + template + static void eval(L const& l, F f, A & a) + { + f(a[l.a1_], a[l.a2_]); + } +}; + +template struct evaluator3 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(a[l.a1_], a[l.a2_], a[l.a3_]); + } +}; + +template <> struct evaluator3 +{ + template + static void eval(L const& l, F f, A & a) + { + f(a[l.a1_], a[l.a2_], a[l.a3_]); + } +}; + +template struct evaluator4 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]); + } +}; + +template <> struct evaluator4 +{ + template + static void eval(L const& l, F f, A & a) + { + f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_]); + } +}; + +template struct evaluator5 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]); + } +}; + +template <> struct evaluator5 +{ + template + static void eval(L const& l, F f, A & a) + { + f(a[l.a1_], a[l.a2_], a[l.a3_], a[l.a4_], a[l.a5_]); + } +}; + +template struct evaluator6 +{ + template + static R eval(L const& l, F f, A & a) + { + return f(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 const& l, F f, A & a) + { + f(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 const& l, F f, A & a) + { + return f(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 const& l, F f, A & a) + { + f(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 const& l, F f, A & a) + { + return f(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 const& l, F f, A & a) + { + f(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 const& l, F f, A & a) + { + return f(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 const& l, F f, A & a) + { + f(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 bind_t_generator +{ + template + struct implementation + { typedef typename result_traits::type result_type; - bind_t(F f, L const & l): f_(f), l_(l) {} + implementation(F f, L const & l): f_(f), l_(l) {} result_type operator()() { list0 a; - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } result_type operator()() const { list0 a; - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1) { list1 a(a1); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1) const { list1 a(a1); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2) { list2 a(a1, a2); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2) const { list2 a(a1, a2); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3) { list3 a(a1, a2, a3); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3) const { list3 a(a1, a2, a3); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) { list4 a(a1, a2, a3, a4); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const { list4 a(a1, a2, a3, a4); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) { list5 a(a1, a2, a3, a4, a5); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const { list5 a(a1, a2, a3, a4, a5); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) { list6 a(a1, a2, a3, a4, a5, a6); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + 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); - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } - + template result_type eval(A & a) { - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template result_type eval(A & a) const { - return l_(type(), f_, a); + typedef typename L::template evaluator::type evaluator; + return evaluator::eval(l_, f_, a); } template void accept(V & v) const @@ -681,7 +907,193 @@ private: F f_; L l_; - bind_t & operator= (bind_t const &); + implementation & operator= (implementation const &); + }; +}; + +template <> +struct bind_t_generator +{ + template + struct implementation + { + typedef typename result_traits::type result_type; + + implementation(F f, L const & l): f_(f), l_(l) {} + + result_type operator()() + { + list0 a; + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + result_type operator()() const + { + list0 a; + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1) + { + list1 a(a1); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1) const + { + list1 a(a1); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2) + { + list2 a(a1, a2); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2) const + { + list2 a(a1, a2); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3) + { + list3 a(a1, a2, a3); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3) const + { + list3 a(a1, a2, a3); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) + { + list4 a(a1, a2, a3, a4); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const + { + list4 a(a1, a2, a3, a4); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) + { + list5 a(a1, a2, a3, a4, a5); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const + { + list5 a(a1, a2, a3, a4, a5); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) + { + list6 a(a1, a2, a3, a4, a5, a6); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + 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); + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type eval(A & a) + { + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template result_type eval(A & a) const + { + typedef typename L::template evaluator::type evaluator; + evaluator::eval(l_, f_, a); + } + + template void accept(V & v) const + { + v(f_); + l_.accept(v); + } + +private: + + F f_; + L l_; + + implementation & operator= (implementation const &); + }; +}; + +template class bind_t + : public bind_t_generator::template implementation +{ + typedef typename bind_t_generator::template implementation base; + public: + bind_t(F f, L const & l): base(f, l) {} }; // add_value