
Christopher Kohlhoff wrote:
I think the following code-snippet in the tutorial could be written more elegantly, through an interface change of the deadline_timer:
{ 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 used.
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; public: 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