Skip to content

Commit 4e1b7cd

Browse files
authored
initial set of core changes for constexpr support (issue splunk#123) (splunk#126)
* initial set of core changes for constexpr support (issue splunk#123) * fixes for constexpr core support based on ci failures (issue splunk#123) * drive by fix for gcc9.2 warning on polymorphic exception * fixes for constexpr core support based on for cpp11 and cpp14 build variants (issue splunk#123) * more fixes for constexpr core support (issue splunk#123) - also fix for issue splunk#124 * next round of changes for constexpr core support (issue splunk#123) * fix last msvc regression for constexpr core * driveby fix to remove detail include * 3rd round of changes for constexpr * yet another msvc fix for cpp14 * minor doc fix for issue splunk#127 - tm_isddst -> tm_isdst * minor doc fix for issue splunk#127 - tm_isddst -> tm_isdst * push constexpr deep into the library including date, ptime (issue splunk#123) * push constexpr deep into the library including date, ptime (issue splunk#123) * fix latests regressions from constexpr changes in older gcc
1 parent 061aec8 commit 4e1b7cd

31 files changed

+495
-397
lines changed

example/local_time/flight.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ int main()
2222
tz_database tz_db;
2323
try {
2424
tz_db.load_from_file("../../data/date_time_zonespec.csv");
25-
}catch(data_not_accessible dna) {
25+
}catch(const data_not_accessible& dna) {
2626
std::cerr << "Error with time zone data file: " << dna.what() << std::endl;
2727
exit(EXIT_FAILURE);
28-
}catch(bad_field_count bfc) {
28+
}catch(const bad_field_count& bfc) {
2929
std::cerr << "Error with time zone data file: " << bfc.what() << std::endl;
3030
exit(EXIT_FAILURE);
3131
}

include/boost/date_time/constrained_value.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,25 @@ namespace CV {
4343
public:
4444
typedef typename value_policies::value_type value_type;
4545
// typedef except_type exception_type;
46-
constrained_value(value_type value) : value_((min)())
46+
BOOST_CXX14_CONSTEXPR constrained_value(value_type value) : value_((min)())
4747
{
4848
assign(value);
4949
}
50-
constrained_value& operator=(value_type v)
50+
BOOST_CXX14_CONSTEXPR constrained_value& operator=(value_type v)
5151
{
5252
assign(v);
5353
return *this;
5454
}
5555
//! Return the max allowed value (traits method)
56-
static value_type max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::max)();}
56+
static BOOST_CONSTEXPR_OR_CONST value_type
57+
max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::max)();}
58+
5759
//! Return the min allowed value (traits method)
58-
static value_type min BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::min)();}
60+
static BOOST_CONSTEXPR_OR_CONST value_type
61+
min BOOST_PREVENT_MACRO_SUBSTITUTION () {return (value_policies::min)();}
62+
5963
//! Coerce into the representation type
60-
operator value_type() const {return value_;}
64+
BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;}
6165
protected:
6266
value_type value_;
6367
private:
@@ -103,8 +107,12 @@ namespace CV {
103107

104108
public:
105109
typedef rep_type value_type;
106-
static rep_type min BOOST_PREVENT_MACRO_SUBSTITUTION () { return min_value; }
107-
static rep_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return max_value; }
110+
static BOOST_CONSTEXPR_OR_CONST rep_type
111+
min BOOST_PREVENT_MACRO_SUBSTITUTION () { return min_value; }
112+
113+
static BOOST_CONSTEXPR_OR_CONST rep_type
114+
max BOOST_PREVENT_MACRO_SUBSTITUTION () { return max_value; }
115+
108116
static void on_error(rep_type, rep_type, violation_enum)
109117
{
110118
boost::throw_exception(actual_exception_type());

include/boost/date_time/date.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,76 +68,76 @@ namespace date_time {
6868
typedef typename calendar::date_rep_type date_rep_type;
6969
typedef typename calendar::date_int_type date_int_type;
7070
typedef typename calendar::day_of_week_type day_of_week_type;
71-
date(year_type y, month_type m, day_type d)
71+
BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
7272
: days_(calendar::day_number(ymd_type(y, m, d)))
7373
{}
74-
date(const ymd_type& ymd)
74+
BOOST_CXX14_CONSTEXPR date(const ymd_type& ymd)
7575
: days_(calendar::day_number(ymd))
7676
{}
7777
//let the compiler write copy, assignment, and destructor
78-
year_type year() const
78+
BOOST_CXX14_CONSTEXPR year_type year() const
7979
{
8080
ymd_type ymd = calendar::from_day_number(days_);
8181
return ymd.year;
8282
}
83-
month_type month() const
83+
BOOST_CXX14_CONSTEXPR month_type month() const
8484
{
8585
ymd_type ymd = calendar::from_day_number(days_);
8686
return ymd.month;
8787
}
88-
day_type day() const
88+
BOOST_CXX14_CONSTEXPR day_type day() const
8989
{
9090
ymd_type ymd = calendar::from_day_number(days_);
9191
return ymd.day;
9292
}
93-
day_of_week_type day_of_week() const
93+
BOOST_CXX14_CONSTEXPR day_of_week_type day_of_week() const
9494
{
9595
ymd_type ymd = calendar::from_day_number(days_);
9696
return calendar::day_of_week(ymd);
9797
}
98-
ymd_type year_month_day() const
98+
BOOST_CXX14_CONSTEXPR ymd_type year_month_day() const
9999
{
100100
return calendar::from_day_number(days_);
101101
}
102-
bool operator<(const date_type& rhs) const
102+
BOOST_CONSTEXPR bool operator<(const date_type& rhs) const
103103
{
104104
return days_ < rhs.days_;
105105
}
106-
bool operator==(const date_type& rhs) const
106+
BOOST_CONSTEXPR bool operator==(const date_type& rhs) const
107107
{
108108
return days_ == rhs.days_;
109109
}
110110
//! check to see if date is a special value
111-
bool is_special()const
111+
BOOST_CONSTEXPR bool is_special()const
112112
{
113113
return(is_not_a_date() || is_infinity());
114114
}
115115
//! check to see if date is not a value
116-
bool is_not_a_date() const
116+
BOOST_CONSTEXPR bool is_not_a_date() const
117117
{
118118
return traits_type::is_not_a_number(days_);
119119
}
120120
//! check to see if date is one of the infinity values
121-
bool is_infinity() const
121+
BOOST_CONSTEXPR bool is_infinity() const
122122
{
123123
return traits_type::is_inf(days_);
124124
}
125125
//! check to see if date is greater than all possible dates
126-
bool is_pos_infinity() const
126+
BOOST_CONSTEXPR bool is_pos_infinity() const
127127
{
128128
return traits_type::is_pos_inf(days_);
129129
}
130130
//! check to see if date is greater than all possible dates
131-
bool is_neg_infinity() const
131+
BOOST_CONSTEXPR bool is_neg_infinity() const
132132
{
133133
return traits_type::is_neg_inf(days_);
134134
}
135135
//! return as a special value or a not_special if a normal date
136-
special_values as_special() const
136+
BOOST_CXX14_CONSTEXPR special_values as_special() const
137137
{
138138
return traits_type::to_special(days_);
139139
}
140-
duration_type operator-(const date_type& d) const
140+
BOOST_CXX14_CONSTEXPR duration_type operator-(const date_type& d) const
141141
{
142142
if (!this->is_special() && !d.is_special())
143143
{
@@ -154,33 +154,33 @@ namespace date_time {
154154
}
155155
}
156156

157-
date_type operator-(const duration_type& dd) const
157+
BOOST_CXX14_CONSTEXPR date_type operator-(const duration_type& dd) const
158158
{
159159
if(dd.is_special())
160160
{
161161
return date_type(date_rep_type(days_) - dd.get_rep());
162162
}
163163
return date_type(date_rep_type(days_) - static_cast<date_int_type>(dd.days()));
164164
}
165-
date_type operator-=(const duration_type& dd)
165+
BOOST_CXX14_CONSTEXPR date_type operator-=(const duration_type& dd)
166166
{
167167
*this = *this - dd;
168168
return date_type(days_);
169169
}
170-
date_rep_type day_count() const
170+
BOOST_CONSTEXPR date_rep_type day_count() const
171171
{
172172
return days_;
173173
}
174174
//allow internal access from operators
175-
date_type operator+(const duration_type& dd) const
175+
BOOST_CXX14_CONSTEXPR date_type operator+(const duration_type& dd) const
176176
{
177177
if(dd.is_special())
178178
{
179179
return date_type(date_rep_type(days_) + dd.get_rep());
180180
}
181181
return date_type(date_rep_type(days_) + static_cast<date_int_type>(dd.days()));
182182
}
183-
date_type operator+=(const duration_type& dd)
183+
BOOST_CXX14_CONSTEXPR date_type operator+=(const duration_type& dd)
184184
{
185185
*this = *this + dd;
186186
return date_type(days_);
@@ -192,8 +192,8 @@ namespace date_time {
192192
dates. It is not exposed to users since that would require class
193193
users to understand the inner workings of the date class.
194194
*/
195-
explicit date(date_int_type days) : days_(days) {}
196-
explicit date(date_rep_type days) : days_(days.as_number()) {}
195+
BOOST_CONSTEXPR explicit date(date_int_type days) : days_(days) {}
196+
BOOST_CXX14_CONSTEXPR explicit date(date_rep_type days) : days_(days.as_number()) {}
197197
date_int_type days_;
198198

199199
};

include/boost/date_time/date_duration.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,50 @@ namespace date_time {
3333
typedef typename duration_rep_traits::impl_type duration_rep;
3434

3535
//! Construct from a day count
36-
explicit date_duration(duration_rep day_count) : days_(day_count) {}
36+
BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count) : days_(day_count) {}
3737

3838
/*! construct from special_values - only works when
3939
* instantiated with duration_traits_adapted */
40-
date_duration(special_values sv) :
40+
BOOST_CXX14_CONSTEXPR date_duration(special_values sv) :
4141
days_(duration_rep::from_special(sv))
4242
{}
4343

4444
// copy constructor required for addable<> & subtractable<>
4545
//! Construct from another date_duration (Copy Constructor)
46-
date_duration(const date_duration<duration_rep_traits>& other) :
46+
BOOST_CXX14_CONSTEXPR date_duration(const date_duration<duration_rep_traits>& other) :
4747
days_(other.days_)
4848
{}
4949

5050
//! returns days_ as it's instantiated type - used for streaming
51-
duration_rep get_rep()const
51+
BOOST_CXX14_CONSTEXPR duration_rep get_rep()const
5252
{
5353
return days_;
5454
}
55-
special_values as_special() const
55+
BOOST_CXX14_CONSTEXPR special_values as_special() const
5656
{
5757
return days_.as_special();
5858
}
59-
bool is_special()const
59+
BOOST_CXX14_CONSTEXPR bool is_special()const
6060
{
6161
return days_.is_special();
6262
}
6363
//! returns days as value, not object.
64-
duration_rep_type days() const
64+
BOOST_CXX14_CONSTEXPR duration_rep_type days() const
6565
{
6666
return duration_rep_traits::as_number(days_);
6767
}
6868
//! Returns the smallest duration -- used by to calculate 'end'
69-
static date_duration unit()
69+
static BOOST_CXX14_CONSTEXPR date_duration unit()
7070
{
7171
return date_duration<duration_rep_traits>(1);
7272
}
7373
//! Equality
74-
bool operator==(const date_duration& rhs) const
74+
BOOST_CXX14_CONSTEXPR bool operator==(const date_duration& rhs) const
7575
{
7676
return days_ == rhs.days_;
7777
}
7878
//! Less
79-
bool operator<(const date_duration& rhs) const
79+
BOOST_CXX14_CONSTEXPR bool operator<(const date_duration& rhs) const
8080
{
8181
return days_ < rhs.days_;
8282
}
@@ -87,33 +87,33 @@ namespace date_time {
8787
* so this will not compile */
8888

8989
//! Subtract another duration -- result is signed
90-
date_duration& operator-=(const date_duration& rhs)
90+
BOOST_CXX14_CONSTEXPR date_duration& operator-=(const date_duration& rhs)
9191
{
9292
//days_ -= rhs.days_;
9393
days_ = days_ - rhs.days_;
9494
return *this;
9595
}
9696
//! Add a duration -- result is signed
97-
date_duration& operator+=(const date_duration& rhs)
97+
BOOST_CXX14_CONSTEXPR date_duration& operator+=(const date_duration& rhs)
9898
{
9999
days_ = days_ + rhs.days_;
100100
return *this;
101101
}
102102

103103
//! unary- Allows for dd = -date_duration(2); -> dd == -2
104-
date_duration operator-() const
104+
BOOST_CXX14_CONSTEXPR date_duration operator-() const
105105
{
106106
return date_duration<duration_rep_traits>(get_rep() * (-1));
107107
}
108108
//! Division operations on a duration with an integer.
109-
date_duration& operator/=(int divisor)
109+
BOOST_CXX14_CONSTEXPR date_duration& operator/=(int divisor)
110110
{
111111
days_ = days_ / divisor;
112112
return *this;
113113
}
114114

115115
//! return sign information
116-
bool is_negative() const
116+
BOOST_CXX14_CONSTEXPR bool is_negative() const
117117
{
118118
return days_ < 0;
119119
}
@@ -130,7 +130,7 @@ namespace date_time {
130130
{
131131
typedef long int_type;
132132
typedef long impl_type;
133-
static int_type as_number(impl_type i) { return i; }
133+
static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i; }
134134
};
135135

136136
/*! Struct for instantiating date_duration <b>WITH</b> special values
@@ -140,7 +140,7 @@ namespace date_time {
140140
{
141141
typedef long int_type;
142142
typedef boost::date_time::int_adapter<long> impl_type;
143-
static int_type as_number(impl_type i) { return i.as_number(); }
143+
static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i.as_number(); }
144144
};
145145

146146

0 commit comments

Comments
 (0)