Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2005-12-21 08:54:42

Christopher Kohlhoff wrote:

>>I think the following code-snippet in the tutorial could be
>>written more elegantly, through an interface change of the
>>{ boost::asio::deadline_timer t; ...
>>t.expires_at(t.expires_at() + boost::posix_time::seconds(1));
>>by giving direct access to the time member.
>>t.expiry_date()+=boost::posix_time::seconds(1); For more
>>complex cases or error-checking, some proxy classes could be
>Doesn't such an approach force a particular internal
>implementation on the timer?
Actually, no. It's pretty easy to write a proxy object to do this stuff.
A minimal object, just for the above example:

class expiry_date_proxy
  deadline_timer &timer;

  expiry_date_proxy(deadline_timer &t) : timer(t) {}

  expiry_date_proxy & operator +=(timespan ts) {
    timer.expires_at(timer.expires_at() + ts);

class deadline_timer
  expiry_date_proxy expiry_date() { return expiry_date_proxy(*this); }

I'm not saying that this necessarily should be done (in particular,
where do you stop making properties?), but it's possible.

Sebastian Redl

Boost list run by bdawes at, gregod at, cpdaniel at, john at