Boost logo

Boost :

From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2008-02-20 10:23:20


From: Korcan Hussein
Sent: 20 February 2008 15:06 To: boost_at_[hidden]
Subject: [boost] [bind] recursively binding higher-order functional
objects fails to compile.

> Sorry about the poor title, it is difficult for me to explain the
> problem without code so here is a really simple example of what i'm
> trying to achieve but fails to compile with Boost.Bind:
>
> #include <boost/bind.hpp>
>
> struct FunFn {
>
> typedef void result_type;
> template < typename Fun >
> void operator()(Fun fn) const {
> fn();
> }
>
> } const Fn;
>
> void g() { std::cout << "hello\n"; }
>
> int main() {
> using namespace boost;
>
> bind(Fn, bind(Fn, bind(Fn, bind(Fn, ... bind(Fn, g))();

Clearly:
      bind(Fn,g)();
works. What about:

      bind(Fn, bind(Fn, g))();

If that works, how many binds can you add before it stops working?
      
>
> }
>
> I get type deduction errors,

You may have run into a compiler limit. What compiler are you using?

> however i have found workaround using
> Boost.Function for the time being:
>
> #include <boost/function.hpp>
>
> ...
> boost::function< void () >
> fnN = bind(Fn, g),
> fnN-1 = bind(Fn, fnN),
> ...,
> fn1 = bind(Fn, fn2),
> fn = bind(Fn, fn1);
>
> bind(Fn, fn)();

-- 
Martin Bonner
Senior Software Engineer/Team Leader
PI SHURLOK LTD
Telephone: +44 1223 441434 / 203894 (direct)
Fax: +44 1223 203999
Email: martin.bonner_at_[hidden]
www.pi-shurlok.com
disclaimer

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk