Gmane
From: Christopher Kohlhoff <chris@...>
Subject: Re: question on serialization example
Newsgroups: gmane.comp.lib.boost.asio.user
Date: 2007-01-09 22:21:08 GMT (1 year, 31 weeks, 6 days, 4 hours and 27 minutes ago)
Hi Themis,

On Tue, 09 Jan 2007 19:41:11 +0200, "Themistoklis Bourdenas"
<themis@...> said:
> So my question is why the tuple is needed? I presume that it's not an 
> asio related problem and it has to do somehow with boost::bind, but 
> since I found the sample code in asio docs, I thought of asking here
> first.

See this section of the boost.bind docs:

http://www.boost.org/libs/bind/bind.html#nested_binds

In summary, the default behaviour is to evaluate nested binds at the
time when the whole bind expression is evaluated. Obviously we don't
want to do this with a handler argument (and trying to do so gives a
compile error since it isn't being passed enough arguments at that point
anyway).

So, we need to hide the nested bind expression from bind. Boost.Bind
provides boost::protect() for this, but:

- The boost::protect() function has an unspecified return value.

- The boost::protect() function only works on some function objects, not
regular function pointers, so it's not generic.

- An equivalent of boost::protect() is not available in TR1, as far as I
can see.

Instead of boost::protect I use the one-argument boost::tuple to wrap
the handler and hide it from bind, but it's basically performing the
same function.

Cheers,
Chris

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV