Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2007-03-14 18:18:08


On Mar 14, 2007, at 5:33 PM, Christopher Kohlhoff wrote:

>
>> What if there existed a:
>>
>> template <class R>
>> template <class F>
>> promise_functor<R, F>
>> promise<R>::operator()(F f);
>>
>> This would be in addition to the current setter functionality in
>> promise.
>
> Hmm, I think I'd prefer a non-member function to make the distinction
> between that act of settingthe promise and the act of composing
> another
> function object clearer when reading the code. I don't see any
> implementation reason to make it a member function - is there one?

No I don't think there's a reason. A friend free function can do
anything a member can. I think we're just looking at syntax:

future<std::string> resolve(std::string host_name)
{
     promise<std::string> result;
     boost::asio::ip::tcp::resolver::query query(host_name, "0");
     resolver_.async_resolve(query,
result(boost::bind(&Resolver::handle_resolve, this, _1, _2)));
     return result;
}

vs:

future<std::string> resolve(std::string host_name)
{
     promise<std::string> result;
     boost::asio::ip::tcp::resolver::query query(host_name, "0");
     resolver_.async_resolve(query, make_promise_functor(result,
boost::bind(&Resolver::handle_resolve, this, _1, _2)));
     return result;
}

-Howard


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