Boost logo

Boost-Commit :

From: hinnant_at_[hidden]
Date: 2007-12-05 12:37:07


Author: hinnant
Date: 2007-12-05 12:37:07 EST (Wed, 05 Dec 2007)
New Revision: 41752
URL: http://svn.boost.org/trac/boost/changeset/41752

Log:
fixed some warnings and typeos in hdate_time
Text files modified:
   sandbox/committee/LWG/ref_impl/hdate_time | 368 ++++++++++++++++++++++-----------------
   1 files changed, 205 insertions(+), 163 deletions(-)

Modified: sandbox/committee/LWG/ref_impl/hdate_time
==============================================================================
--- sandbox/committee/LWG/ref_impl/hdate_time (original)
+++ sandbox/committee/LWG/ref_impl/hdate_time 2007-12-05 12:37:07 EST (Wed, 05 Dec 2007)
@@ -552,416 +552,458 @@
 };
 
 template <class To>
-struct __make
+class __make
 {
     template <class Duration>
+ static To
+ __from(const Duration& t, true_type, true_type)
+ {
+ return To(t.get_count() * To::ticks_per_second / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static To
+ __from(const Duration& t, false_type, true_type)
+ {
+ return To(t.get_count() / To::seconds_per_tick / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static To
+ __from(const Duration& t, true_type, false_type)
+ {
+ return To(t.get_count() * To::ticks_per_second * Duration::seconds_per_tick);
+ }
+
+ template <class Duration>
+ static To
+ __from(const Duration& t, false_type, false_type)
+ {
+ return To(t.get_count() * Duration::seconds_per_tick / To::seconds_per_tick);
+ }
+public:
+ template <class Duration>
     static
     To
     from(const Duration& t)
     {
- long long r;
- if (To::Duration::is_subsecond && Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * To::ticks_per_second / Duration::ticks_per_second);
- }
- else if (!To::Duration::is_subsecond && Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() / To::ticks_per_second / Duration::ticks_per_second);
- }
- else if (To::Duration::is_subsecond && !Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * To::ticks_per_second * Duration::ticks_per_second);
- }
- else // if (!To::Duration::is_subsecond && !Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * Duration::ticks_per_second / To::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, To::is_subsecond>(),
+ integral_constant<bool, Duration::is_subsecond>());
     }
 };
 
 template <>
-struct __make<nanoseconds>
+class __make<nanoseconds>
 {
     template <class Duration>
+ static nanoseconds
+ __from(const Duration& t, true_type)
+ {
+ return nanoseconds(t.get_count() * nanoseconds::ticks_per_second / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static nanoseconds
+ __from(const Duration& t, false_type)
+ {
+ return nanoseconds(t.get_count() * nanoseconds::ticks_per_second * Duration::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     nanoseconds
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * nanoseconds::ticks_per_second / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * nanoseconds::ticks_per_second * Duration::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     nanoseconds
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count() * 3600000000000LL;
+ return t;
     }
 
     static
     nanoseconds
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count() * 60000000000LL;
+ return nanoseconds(t.get_count() * 1000LL);
     }
 
     static
     nanoseconds
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count() * 1000000000LL;
+ return nanoseconds(t.get_count() * 1000000LL);
     }
 
     static
     nanoseconds
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count() * 1000000LL;
+ return nanoseconds(t.get_count() * 1000000000LL);
     }
 
     static
     nanoseconds
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count() * 1000LL;
+ return nanoseconds(t.get_count() * 60000000000LL);
     }
 
     static
     nanoseconds
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count();
+ return nanoseconds(t.get_count() * 3600000000000LL);
     }
-
 };
 
 template <>
-struct __make<microseconds>
+class __make<microseconds>
 {
     template <class Duration>
+ static microseconds
+ __from(const Duration& t, true_type)
+ {
+ return microseconds(t.get_count() * microseconds::ticks_per_second / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static microseconds
+ __from(const Duration& t, false_type)
+ {
+ return microseconds(t.get_count() * microseconds::ticks_per_second * Duration::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     microseconds
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * microseconds::ticks_per_second / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * microseconds::ticks_per_second * Duration::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     microseconds
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count() * 3600000000LL;
+ return microseconds(t.get_count() / 1000LL);
     }
 
     static
     microseconds
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count() * 60000000LL;
+ return t;
     }
 
     static
     microseconds
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count() * 1000000LL;
+ return microseconds(t.get_count() * 1000LL);
     }
 
     static
     microseconds
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count() * 1000LL;
+ return microseconds(t.get_count() * 1000000LL);
     }
 
     static
     microseconds
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count();
+ return microseconds(t.get_count() * 60000000LL);
     }
 
     static
     microseconds
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count() / 1000LL;
+ return microseconds(t.get_count() * 3600000000LL);
     }
-
 };
 
 template <>
-struct __make<milliseconds>
+class __make<milliseconds>
 {
     template <class Duration>
+ static milliseconds
+ __from(const Duration& t, true_type)
+ {
+ return milliseconds(t.get_count() * milliseconds::ticks_per_second / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static milliseconds
+ __from(const Duration& t, false_type)
+ {
+ return milliseconds(t.get_count() * milliseconds::ticks_per_second * Duration::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     milliseconds
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * milliseconds::ticks_per_second / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * milliseconds::ticks_per_second * Duration::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     milliseconds
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count() * 3600000LL;
+ return milliseconds(t.get_count() / 1000000LL);
     }
 
     static
     milliseconds
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count() * 60000LL;
+ return milliseconds(t.get_count() / 1000LL);
     }
 
     static
     milliseconds
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count() * 1000LL;
+ return t;
     }
 
     static
     milliseconds
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count();
+ return milliseconds(t.get_count() * 1000LL);
     }
 
     static
     milliseconds
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count() / 1000LL;
+ return milliseconds(t.get_count() * 60000LL);
     }
 
     static
     milliseconds
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count() / 1000000LL;
+ return milliseconds(t.get_count() * 3600000LL);
     }
-
 };
 
 template <>
-struct __make<seconds>
+class __make<seconds>
 {
     template <class Duration>
+ static seconds
+ __from(const Duration& t, true_type)
+ {
+ return seconds(t.get_count() / seconds::seconds_per_tick / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static seconds
+ __from(const Duration& t, false_type)
+ {
+ return seconds(t.get_count() * Duration::seconds_per_tick / seconds::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     seconds
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * Duration::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     seconds
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count() * 3600LL;
+ return seconds(t.get_count() / 1000000000LL);
     }
 
     static
     seconds
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count() * 60LL;
+ return seconds(t.get_count() / 1000000LL);
     }
 
     static
     seconds
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count();
+ return seconds(t.get_count() / 1000LL);
     }
 
     static
     seconds
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count() / 1000LL;
+ return t;
     }
 
     static
     seconds
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count() / 1000000LL;
+ return seconds(t.get_count() * 60LL);
     }
 
     static
     seconds
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count() / 1000000000LL;
+ return seconds(t.get_count() * 3600LL);
     }
-
 };
 
 template <>
-struct __make<minutes>
+class __make<minutes>
 {
     template <class Duration>
+ static minutes
+ __from(const Duration& t, true_type)
+ {
+ return minutes(t.get_count() / minutes::seconds_per_tick / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static minutes
+ __from(const Duration& t, false_type)
+ {
+ return minutes(t.get_count() * Duration::seconds_per_tick / minutes::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     minutes
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() / minutes::ticks_per_second / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * Duration::ticks_per_second / minutes::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     minutes
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count() * 60LL;
+ return minutes(t.get_count() / 60000000000LL);
     }
 
     static
     minutes
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count();
+ return minutes(t.get_count() / 60000000L);
     }
 
     static
     minutes
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count() / 60LL;
+ return minutes(t.get_count() / 60000L);
     }
 
     static
     minutes
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count() / 60000LL;
+ return minutes(t.get_count() / 60L);
     }
 
     static
     minutes
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count() / 60000000LL;
+ return t;
     }
 
     static
     minutes
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count() / 60000000000LL;
+ return minutes(t.get_count() * 60L);
     }
-
 };
 
 template <>
-struct __make<hours>
+class __make<hours>
 {
     template <class Duration>
+ static hours
+ __from(const Duration& t, true_type)
+ {
+ return hours(t.get_count() / hours::seconds_per_tick / Duration::ticks_per_second);
+ }
+
+ template <class Duration>
+ static hours
+ __from(const Duration& t, false_type)
+ {
+ return hours(t.get_count() * Duration::seconds_per_tick / hours::seconds_per_tick);
+ }
+
+public:
+ template <class Duration>
     static
     hours
     from(const Duration& t)
     {
- long long r;
- if (Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() / hours::ticks_per_second / Duration::ticks_per_second);
- }
- else // if (!Duration::is_subsecond)
- {
- r = static_cast<long long>(t.get_count() * Duration::ticks_per_second / hours::ticks_per_second);
- }
- return r;
+ return __from(t, integral_constant<bool, Duration::is_subsecond>());
     }
 
     static
     hours
- from(const hours& t)
+ from(const nanoseconds& t)
     {
- return t.get_count();
+ return hours(t.get_count() / 3600000000000LL);
     }
 
     static
     hours
- from(const minutes& t)
+ from(const microseconds& t)
     {
- return t.get_count() / 60LL;
+ return hours(t.get_count() / 3600000000LL);
     }
 
     static
     hours
- from(const seconds& t)
+ from(const milliseconds& t)
     {
- return t.get_count() / 3600LL;
+ return hours(t.get_count() / 3600000L);
     }
 
     static
     hours
- from(const milliseconds& t)
+ from(const seconds& t)
     {
- return t.get_count() / 3600000LL;
+ return hours(t.get_count() / 3600L);
     }
 
     static
     hours
- from(const microseconds& t)
+ from(const minutes& t)
     {
- return t.get_count() / 3600000000LL;
+ return hours(t.get_count() / 60L);
     }
 
     static
     hours
- from(const nanoseconds& t)
+ from(const hours& t)
     {
- return t.get_count() / 3600000000000LL;
+ return t;
     }
-
 };
 
 template <class LhsDuration, class RhsDuration,


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