Boost logo

Boost :

Subject: [boost] [date_time] default constructor for period?
From: Scott Bailey (Bailey_at_[hidden])
Date: 2015-04-29 18:27:15

I would like to use this:

But std::deque depends on (as does some of my other code) it's type having
a default constructor. I'm surprised it does not already exists.

An implementation that seems to work for me is trivial, although I'm not
sure it will work for everyone?

My changes to 'boost/date_time_time_period.hpp' follow. I have guarded
them with DATE_TIME_NO_DEFAULT_CONSTRUCTOR and simply set begin to
point_type() and end to begin_ -1;

Is this a change worth an eventual release?


--- a/period.hpp 2015-04-29 15:13:28.040930833 -0700
+++ b/period.hpp 2015-04-29 15:15:01.201392793 -0700
@@ -57,6 +57,9 @@
     typedef point_rep point_type;
     typedef duration_rep duration_type;

+ period();
     period(point_rep first_point, point_rep end_point);
     period(point_rep first_point, duration_rep len);
     point_rep begin() const;
@@ -82,6 +85,16 @@
     point_rep last_;

+ //! default constructor
+ template<class point_rep, class duration_rep>
+ inline
+ period<point_rep,duration_rep>::period() :
+ begin_(point_type()),
+ last_(begin_ - duration_rep::unit())
+ {}
   //! create a period from begin to last eg: [begin,end)
   /*! If end <= begin then the period will be invalid

Scott Bailey

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