plus<boost::gregorian::date> - how to?
I need to be able to either add or substruct boost::gregorian::days from boost::gregorian::date. As far as I understand I have to define plusboost::gregorian::date and miniusboost::gregorian::date and provide function operators for them. My question is: Function operator required in plus and minus template has a form of T operator()(const T& x, const T& y) , but I need to use not only gregorian::date, but gregorian::days as well. Any advise is greatly appreciated.
qplace wrote:
I need to be able to either add or substruct boost::gregorian::days from boost::gregorian::date.
As far as I understand I have to define plusboost::gregorian::date and miniusboost::gregorian::date and provide function operators for them.
My question is: Function operator required in plus and minus template has a form of T operator()(const T& x, const T& y) , but I need to use not only gregorian::date, but gregorian::days as well.
Sometimes it's perfectly reasonable to allow adding operands of different types, for example also when incrementing a random access iterator. In such a case you can just use parameters of different types and keep the rest of the semantics the same. Like this: namespace bg = boost::gregorian; bg::date operator+ (const bg::date&, const bg::days&); bg::date operator- (const bg::date&, const bg::days&); and perhaps also bg::date operator+ (const bg::days&, const bg::date&); bg::date operator- (const bg::days&, const bg::date&); You can't use std::plus and std::minus in this way, but you only need those when the operation has to be passed as a function object to another function. HTH, Julian
participants (2)
-
Julian Gonggrijp
-
qplace