|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84256 - in sandbox/chrono_date: boost/chrono/date libs/date/src
From: vicente.botet_at_[hidden]
Date: 2013-05-12 16:13:36
Author: viboes
Date: 2013-05-12 16:13:35 EDT (Sun, 12 May 2013)
New Revision: 84256
URL: http://svn.boost.org/trac/boost/changeset/84256
Log:
Chrono/Date: Make is_invalid ymd_date(y, md) constexpr.
Text files modified:
sandbox/chrono_date/boost/chrono/date/conversions.hpp | 5 +
sandbox/chrono_date/boost/chrono/date/ymd_date.hpp | 102 ++++++++++++++++++++++++++++++---------
sandbox/chrono_date/libs/date/src/conversions.cpp | 21 +++++++-
sandbox/chrono_date/libs/date/src/ymd_date.cpp | 58 ++++++++--------------
4 files changed, 121 insertions(+), 65 deletions(-)
Modified: sandbox/chrono_date/boost/chrono/date/conversions.hpp
==============================================================================
--- sandbox/chrono_date/boost/chrono/date/conversions.hpp (original)
+++ sandbox/chrono_date/boost/chrono/date/conversions.hpp 2013-05-12 16:13:35 EDT (Sun, 12 May 2013)
@@ -42,8 +42,9 @@
days::rep to_days(int_least32_t y, int_least16_t m, int_least16_t d, bool) BOOST_NOEXCEPT;
void to_ymd(days::rep dt, int& y, int& m, int& d) BOOST_NOEXCEPT;
void to_ymd(days::rep dt, int_least32_t& y, int_least16_t& m, int_least16_t& d) BOOST_NOEXCEPT;
- void to_ymdl(days::rep dt, int_least32_t& y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT;
- //int_least16_t to_ymdl(days::rep dt, int_least32_t y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT;
+ void to_ymd_leap(days::rep dt, int_least32_t& y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT;
+ void to_ymd_leap(days::rep dt, int_least16_t& y, int_least8_t& m, int_least8_t& d, bool& leap) BOOST_NOEXCEPT;
+ //int_least16_t to_ymd_leap(days::rep dt, int_least32_t y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT;
days to_days(year_month_day) BOOST_NOEXCEPT;
days to_days(year_day_of_year) BOOST_NOEXCEPT;
Modified: sandbox/chrono_date/boost/chrono/date/ymd_date.hpp
==============================================================================
--- sandbox/chrono_date/boost/chrono/date/ymd_date.hpp (original)
+++ sandbox/chrono_date/boost/chrono/date/ymd_date.hpp 2013-05-12 16:13:35 EDT (Sun, 12 May 2013)
@@ -96,44 +96,79 @@
public:
#if ! defined BOOST_CHRONO_DATE_DOXYGEN_INVOKED
+ private:
-#ifndef BOOST_NO_CXX11_CONSTEXPR
+ /**
+ * Check the validity between the parameters not that the parameters are them self valid.
+ */
BOOST_FORCEINLINE static BOOST_CHRONO_DATE_CONSTEXPR
- day check_invariants(year y, month m, day d)
+ bool is_valid_(year y, month m, day d)
{
return (m != 2)
? ( d <= chrono_detail::max_days_in_month(m)
- ? d
- : throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m))
+ ? true
+ : false
)
: ( y.is_leap()
? ( d <= 29
- ? d
- : throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m))
+ ? true
+ : false
)
: ( d <= 28
- ? d
- : throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m))
+ ? true
+ : false
)
);
}
+ BOOST_FORCEINLINE static BOOST_CHRONO_DATE_CONSTEXPR
+ bool is_valid_(year y, month_day md)
+ {
+ return month(md) != 2 || day(md) <= 28 || y.is_leap()
+ ? true
+ : false;
+ }
+
+#ifndef BOOST_NO_CXX11_CONSTEXPR
+ BOOST_FORCEINLINE static BOOST_CHRONO_DATE_CONSTEXPR
+ day check_invariants(year y, month m, day d)
+ {
+ return is_valid_(y,m,d)
+ ? d
+ : throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m))
+ ;
+ }
+
+ BOOST_FORCEINLINE static BOOST_CHRONO_DATE_CONSTEXPR
+ day check_invariants(year y, month_day md)
+ {
+ return is_valid_(y,md)
+ ? day(md)
+ : throw bad_date("day " + to_string(day(md)) + " is out of range for " + to_string(y) + '/' + to_string(month(md)))
+ ;
+ }
+
#else
BOOST_FORCEINLINE static
day check_invariants(year y, month m, day d)
{
- if ( m != 2 )
- if ( d <= chrono_detail::max_days_in_month(m) ) return d;
- else throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m));
- else
- if (y.is_leap())
- if ( d <= 29 ) return d;
- else throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m));
- else
- if (d <= 28) return d;
- else throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m));
+ if ( is_valid_(y,m,d) )
+ return d;
+ else throw bad_date("day " + to_string(d) + " is out of range for " + to_string(y) + '/' + to_string(m));
+ }
+
+ BOOST_FORCEINLINE static
+ day check_invariants(year y, month_day md)
+ {
+ if ( is_valid_(y,md) )
+ return day(md);
+ else throw bad_date("day " + to_string(day(md)) + " is out of range for " + to_string(y) + '/' + to_string(month(md)));
}
#endif
+
+
+
+
#endif
/**
* @Effect Constructs a @c ymd_date using the @c year, @c month, @c day stored in the arguments as follows:
@@ -152,7 +187,7 @@
#endif
{
}
- ymd_date(int y, chrono::month m, chrono::day d, check_t):
+ BOOST_FORCEINLINE BOOST_CHRONO_DATE_CONSTEXPR ymd_date(int y, chrono::month m, chrono::day d, check_t):
y_(y),
m_(m),
d_(check_invariants(year(y), m, d))
@@ -161,7 +196,7 @@
#endif
{
}
- ymd_date(chrono::year y, int m, chrono::day d, check_t):
+ BOOST_FORCEINLINE BOOST_CHRONO_DATE_CONSTEXPR ymd_date(chrono::year y, int m, chrono::day d, check_t):
y_(y),
m_(m),
d_(check_invariants(y, month(m), d))
@@ -304,13 +339,29 @@
* @Throws bad_date if the specified ymd_date is invalid.
* @Note This constructor can be more efficient as the month_day is already valid.
*/
- ymd_date(chrono::year y, month_day md, check_t);
+ BOOST_FORCEINLINE BOOST_CHRONO_DATE_CONSTEXPR ymd_date(chrono::year y, month_day md, check_t):
+ y_(y),
+ m_(month(md)),
+ d_(check_invariants(y, md))
+#if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
+ , leap_(y.is_leap())
+#endif
+ {
+ }
/**
* @Effect Constructs a ymd_date using the year, month_day stored in the arguments as follows:
* Constructs a ymd_date for which year() == y, month() == month(md), day() == month(md).
* @Note This constructor can be more efficient as the month_day is already valid.
*/
- ymd_date(chrono::year, month_day) BOOST_NOEXCEPT;
+ BOOST_FORCEINLINE BOOST_CHRONO_DATE_CONSTEXPR ymd_date(chrono::year y, month_day md) BOOST_NOEXCEPT:
+ y_(y),
+ m_(month(md)),
+ d_(day(md))
+ #if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
+ , leap_(y.is_leap())
+ #endif
+ {
+ }
// /**
// * @Effect Constructs a ymd_date using the year, day_of_year stored in the arguments as follows:
@@ -434,7 +485,10 @@
* @Returns whether the year()/month()/day() is a valid proleptic Gregorian date.
*/
// @todo BOOST_CONSTEXPR
- bool is_valid() const BOOST_NOEXCEPT;
+ BOOST_FORCEINLINE BOOST_CHRONO_DATE_CONSTEXPR bool is_valid() const BOOST_NOEXCEPT
+ {
+ return month(m_).is_valid() && day(d_).is_valid() && is_valid_(year(y_), month(m_), day(d_));
+ }
//#if ! defined BOOST_CHRONO_DATE_DOXYGEN_INVOKED
// private:
@@ -537,7 +591,7 @@
BOOST_FORCEINLINE BOOST_CONSTEXPR bool is_leap_year() const BOOST_NOEXCEPT
{
#if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
- return leap_;
+ return leap_;
#else
return is_leap(y_);
#endif
Modified: sandbox/chrono_date/libs/date/src/conversions.cpp
==============================================================================
--- sandbox/chrono_date/libs/date/src/conversions.cpp (original)
+++ sandbox/chrono_date/libs/date/src/conversions.cpp 2013-05-12 16:13:35 EDT (Sun, 12 May 2013)
@@ -88,7 +88,7 @@
d = day_of_year_day_of_month(leap,doy+1);
}
-// int_least16_t to_ymdl(days::rep x_, int_least32_t y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT
+// int_least16_t to_ymd_leap(days::rep x_, int_least32_t y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT
// {
// y = static_cast<int_least32_t>(static_cast<int64_t>(x_ + 2) * 400 / 146097);
// int doy = x_ - days_before_year(y);
@@ -104,7 +104,7 @@
// d = day_of_year_day_of_month(leap,doy+1);
// return y;
// }
- void to_ymdl(days::rep x_, int_least32_t& y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT
+ void to_ymd_leap(days::rep x_, int_least32_t& y, int_least16_t& m, int_least16_t& d, bool& leap) BOOST_NOEXCEPT
{
y = static_cast<int_least32_t>(static_cast<int64_t>(x_ + 2) * 400 / 146097);
int doy = x_ - days_before_year(y);
@@ -119,7 +119,22 @@
m = day_of_year_month(leap,doy+1);
d = day_of_year_day_of_month(leap,doy+1);
}
-
+ void to_ymd_leap(days::rep x_, int_least16_t& y, int_least8_t& m, int_least8_t& d, bool& leap) BOOST_NOEXCEPT
+ {
+ int_least32_t y32 = static_cast<int_least32_t>(static_cast<int64_t>(x_ + 2) * 400 / 146097);
+ int doy = x_ - days_before_year(y32);
+ if (doy < 0)
+ {
+ --y32;
+ doy = x_ - days_before_year(y32);
+ }
+ //y += (year::first_-1);
+ y32 -= 32799;
+ leap = is_leap(y32);
+ y = static_cast<int_least16_t>(y32);
+ m = day_of_year_month(leap,doy+1);
+ d = day_of_year_day_of_month(leap,doy+1);
+ }
year_month_day to_ymd(days dt) BOOST_NOEXCEPT
{
days::rep x_ = dt.count();
Modified: sandbox/chrono_date/libs/date/src/ymd_date.cpp
==============================================================================
--- sandbox/chrono_date/libs/date/src/ymd_date.cpp (original)
+++ sandbox/chrono_date/libs/date/src/ymd_date.cpp 2013-05-12 16:13:35 EDT (Sun, 12 May 2013)
@@ -46,24 +46,24 @@
return system_clock::from_time_t(t);
}
- bool ymd_date::is_valid() const BOOST_NOEXCEPT
- {
- //if (chrono::year(y_).is_valid() && chrono::month(m_).is_valid() && chrono::day(d_).is_valid())
- {
- const day_of_year::rep* year_data = days_in_year_before(is_leap_year());
-
- if (! (1 <= d_ && d_ <= year_data[m_] - year_data[m_ - 1]))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- return false;
-
- }
+// bool ymd_date::is_valid() const BOOST_NOEXCEPT
+// {
+// //if (chrono::year(y_).is_valid() && chrono::month(m_).is_valid() && chrono::day(d_).is_valid())
+// {
+// const day_of_year::rep* year_data = days_in_year_before(is_leap_year());
+//
+// if (! (1 <= d_ && d_ <= year_data[m_] - year_data[m_ - 1]))
+// {
+// return false;
+// }
+// else
+// {
+// return true;
+// }
+// }
+// return false;
+//
+// }
bool ymd_date::set_if_valid_date(chrono::year y, chrono::month m, chrono::day d) BOOST_NOEXCEPT
{
@@ -109,20 +109,6 @@
// return true;
// }
- ymd_date::ymd_date(chrono::year y, chrono::month_day md, check_t)
- {
- if (set_if_valid_date(y, month(md), day(md))) return;
- throw bad_date(
- "day " + to_string(day(md)) + " is out of range for " + to_string(y) + '-' + to_string(month(md)));
- }
-
- ymd_date::ymd_date(chrono::year y, chrono::month_day md)BOOST_NOEXCEPT
- : y_(y), m_(month(md)), d_(day(md))
-#if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
- , leap_(is_leap(y_))
-#endif
- {
- }
// ymd_date::ymd_date(chrono::year y, day_of_year doy) BOOST_NOEXCEPT
// {
@@ -163,14 +149,14 @@
{
#if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
//#if ! defined __clang__
-#if 1
+#if 0
year_month_day_leap ymdl = to_ymd_leap(dt.days_since_epoch());
y_=year(ymdl);
m_=month(ymdl);
d_=day(ymdl);
leap_=ymdl.is_leap_year();
#else
- to_ymdl(dt.days_since_epoch().count(), y_,m_,d_,leap_);
+ to_ymd_leap(dt.days_since_epoch().count(), y_,m_,d_,leap_);
#endif
#else
to_ymd(dt.days_since_epoch().count(), y_,m_,d_);
@@ -181,14 +167,14 @@
{
#if defined BOOST_CHRONO_DATE_YMD_DATE_HAS_LEAP_FIELD
//#if ! defined __clang__
-#if 1
+#if 0
year_month_day_leap ymdl = to_ymd_leap(d);
leap_=ymdl.is_leap_year();
y_=year(ymdl);
m_=month(ymdl);
d_=day(ymdl);
#else
- to_ymdl(d.count(), y_,m_,d_,leap_);
+ to_ymd_leap(d.count(), y_,m_,d_,leap_);
#endif
#else
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk