|
Boost : |
Subject: Re: [boost] Futures Review - Allowing partial specialization of wait_for_any
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-16 12:48:08
Hi,
The functions wait_for_all and wait_for_any seams quite generic and could be applied to other asynchronous completion tokens (ACT), as for example the tp::task from Boost.ThreadPool.
In order to do that we need to be able to partialy specialize these functions or use traits:
Let me start with a partial specialization proposal
template<typename F1,typename F2,typename F3>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3)
{
return partial_specialization_workaround::wait_for_any::apply(f1,f2, f3);
}
namespace partial_specialization_workaround {
template<typename Types>
struct wait_for_any;
template<typename F1,typename F2,typename F3>
struct wait_for_any<vector3<F1,F2,F3> > {
unsigned apply(F1& f1,F2& f2,F3& f3) {
detail::future_waiter waiter;
waiter.add(f1);
waiter.add(f2);
waiter.add(f3);
return waiter.wait();
}
};
}
With traits thing simpler . The traits class will have a function that gets a unique/shared_future from the ACT.
template<typename F1,typename F2>
typename boost::enable_if<is_future_type<F1>,unsigned>::type wait_for_any(F1& f1,F2& f2)
{
detail::future_waiter waiter;
waiter.add(traits::get_future(f1));
waiter.add(traits::get_future(f2));
return waiter.wait();
}
The default get_future traits will return its parameter
template <typename ACT>
struct traits {
ACT& get_future(ACT& act) { return act; }
};
What do you think?
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk