Reversed order of arguments to clock_time_conversion.

Now the order of argument matches the clock_cast function.
The test only is_clock_castable trait still matches is_convertible
order of arguments.
This commit is contained in:
Tomasz Kamiński 2017-11-25 22:14:51 +01:00 committed by Howard Hinnant
parent 7c69f1570d
commit 543315b700
8 changed files with 51 additions and 51 deletions

View File

@ -1839,7 +1839,7 @@ public:
static time_point now(); static time_point now();
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<std::chrono::system_clock, typename std::common_type<Duration, std::chrono::seconds>::type> std::chrono::time_point<std::chrono::system_clock, typename std::common_type<Duration, std::chrono::seconds>::type>
to_sys(const std::chrono::time_point<utc_clock, Duration>&); to_sys(const std::chrono::time_point<utc_clock, Duration>&);
@ -1990,7 +1990,7 @@ public:
static time_point now() NOEXCEPT; static time_point now() NOEXCEPT;
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<utc_clock, typename std::common_type<Duration, std::chrono::seconds>::type> std::chrono::time_point<utc_clock, typename std::common_type<Duration, std::chrono::seconds>::type>
to_utc(const std::chrono::time_point<tai_clock, Duration>&) NOEXCEPT; to_utc(const std::chrono::time_point<tai_clock, Duration>&) NOEXCEPT;
@ -2100,7 +2100,7 @@ public:
static time_point now() NOEXCEPT; static time_point now() NOEXCEPT;
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<utc_clock, typename std::common_type<Duration, std::chrono::seconds>::type> std::chrono::time_point<utc_clock, typename std::common_type<Duration, std::chrono::seconds>::type>
to_utc(const std::chrono::time_point<gps_clock, Duration>&) NOEXCEPT; to_utc(const std::chrono::time_point<gps_clock, Duration>&) NOEXCEPT;
@ -2197,7 +2197,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
return is; return is;
} }
template<typename SourceClock, typename DestClock> template<typename DestClock, typename SourceClock>
struct clock_time_conversion struct clock_time_conversion
{}; {};
@ -2207,7 +2207,7 @@ struct clock_time_conversion<std::chrono::system_clock, std::chrono::system_cloc
template <class Duration> template <class Duration>
auto operator()(const sys_time<Duration>& st) const auto operator()(const sys_time<Duration>& st) const
-> sys_time<Duration> -> sys_time<Duration>
{ {
return st; return st;
} }
}; };
@ -2218,13 +2218,13 @@ struct clock_time_conversion<utc_clock, utc_clock>
template <class Duration> template <class Duration>
auto operator()(const utc_time<Duration>& ut) const auto operator()(const utc_time<Duration>& ut) const
-> utc_time<Duration> -> utc_time<Duration>
{ {
return ut; return ut;
} }
}; };
template<> template<>
struct clock_time_conversion<std::chrono::system_clock, utc_clock> struct clock_time_conversion<utc_clock, std::chrono::system_clock>
{ {
template <class Duration> template <class Duration>
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type> utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
@ -2235,7 +2235,7 @@ struct clock_time_conversion<std::chrono::system_clock, utc_clock>
}; };
template<> template<>
struct clock_time_conversion<utc_clock, std::chrono::system_clock> struct clock_time_conversion<std::chrono::system_clock, utc_clock>
{ {
template <class Duration> template <class Duration>
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type> sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
@ -2251,14 +2251,14 @@ struct clock_time_conversion<Clock, Clock>
template <class Duration> template <class Duration>
auto operator()(const std::chrono::time_point<Clock, Duration>& tp) const auto operator()(const std::chrono::time_point<Clock, Duration>& tp) const
-> std::chrono::time_point<Clock, Duration> -> std::chrono::time_point<Clock, Duration>
{ {
return tp; return tp;
} }
}; };
namespace ctc_detail namespace ctc_detail
{ {
//Check if TimePoint is time for given clock, //Check if TimePoint is time for given clock,
//if not emits hard error //if not emits hard error
template<typename Clock, typename TimePoint> template<typename Clock, typename TimePoint>
struct return_clock_time struct return_clock_time
@ -2271,7 +2271,7 @@ namespace ctc_detail
// Check if Clock has to_sys method accepting TimePoint with given duration const& and returning sys_time // Check if Clock has to_sys method accepting TimePoint with given duration const& and returning sys_time
// If so has nested type member equal to return type to_sys. // If so has nested type member equal to return type to_sys.
template<typename Clock, typename Duration, typename = void> template<typename Clock, typename Duration, typename = void>
struct return_to_sys struct return_to_sys
{}; {};
template<typename Clock, typename Duration> template<typename Clock, typename Duration>
@ -2281,7 +2281,7 @@ namespace ctc_detail
// Similiar to above // Similiar to above
template<typename Clock, typename Duration, typename = void> template<typename Clock, typename Duration, typename = void>
struct return_from_sys struct return_from_sys
{}; {};
template<typename Clock, typename Duration> template<typename Clock, typename Duration>
@ -2291,7 +2291,7 @@ namespace ctc_detail
// Similiar to above // Similiar to above
template<typename Clock, typename Duration, typename = void> template<typename Clock, typename Duration, typename = void>
struct return_to_utc struct return_to_utc
{}; {};
template<typename Clock, typename Duration> template<typename Clock, typename Duration>
@ -2301,7 +2301,7 @@ namespace ctc_detail
// Similiar to above // Similiar to above
template<typename Clock, typename Duration, typename = void> template<typename Clock, typename Duration, typename = void>
struct return_from_utc struct return_from_utc
{}; {};
template<typename Clock, typename Duration> template<typename Clock, typename Duration>
@ -2311,7 +2311,7 @@ namespace ctc_detail
} }
template<typename SourceClock> template<typename SourceClock>
struct clock_time_conversion<SourceClock, std::chrono::system_clock> struct clock_time_conversion<std::chrono::system_clock, SourceClock>
{ {
template <class Duration> template <class Duration>
auto operator()(const std::chrono::time_point<SourceClock, Duration>& tp) const auto operator()(const std::chrono::time_point<SourceClock, Duration>& tp) const
@ -2322,7 +2322,7 @@ struct clock_time_conversion<SourceClock, std::chrono::system_clock>
}; };
template<typename DestClock> template<typename DestClock>
struct clock_time_conversion<std::chrono::system_clock, DestClock> struct clock_time_conversion<DestClock, std::chrono::system_clock>
{ {
template <class Duration> template <class Duration>
auto operator()(const sys_time<Duration>& st) const auto operator()(const sys_time<Duration>& st) const
@ -2333,7 +2333,7 @@ struct clock_time_conversion<std::chrono::system_clock, DestClock>
}; };
template<typename SourceClock> template<typename SourceClock>
struct clock_time_conversion<SourceClock, utc_clock> struct clock_time_conversion<utc_clock, SourceClock>
{ {
template <class Duration> template <class Duration>
auto operator()(const std::chrono::time_point<SourceClock, Duration>& tp) const auto operator()(const std::chrono::time_point<SourceClock, Duration>& tp) const
@ -2344,7 +2344,7 @@ struct clock_time_conversion<SourceClock, utc_clock>
}; };
template<typename DestClock> template<typename DestClock>
struct clock_time_conversion<utc_clock, DestClock> struct clock_time_conversion<DestClock, utc_clock>
{ {
template <class Duration> template <class Duration>
auto operator()(const utc_time<Duration>& ut) const auto operator()(const utc_time<Duration>& ut) const
@ -2358,12 +2358,12 @@ namespace clock_cast_detail
{ {
template<typename DestClock, typename SourceClock, typename Duration> template<typename DestClock, typename SourceClock, typename Duration>
auto conv_clock(const std::chrono::time_point<SourceClock, Duration>& st) auto conv_clock(const std::chrono::time_point<SourceClock, Duration>& st)
-> decltype(std::declval<clock_time_conversion<SourceClock, DestClock>>()(st)) -> decltype(std::declval<clock_time_conversion<DestClock, SourceClock>>()(st))
{ {
return clock_time_conversion<SourceClock, DestClock>{}(st); return clock_time_conversion<DestClock, SourceClock>{}(st);
} }
//direct triat conversion, 2nd candidate //direct triat conversion, 2nd candidate
template<typename DestClock, typename SourceClock, typename Duration> template<typename DestClock, typename SourceClock, typename Duration>
auto cc_impl(const std::chrono::time_point<SourceClock, Duration>& st, auto cc_impl(const std::chrono::time_point<SourceClock, Duration>& st,
const std::chrono::time_point<SourceClock, Duration>* /* 1st */) const std::chrono::time_point<SourceClock, Duration>* /* 1st */)
@ -2412,8 +2412,8 @@ namespace clock_cast_detail
template<typename DestClock, typename SourceClock, typename Duration> template<typename DestClock, typename SourceClock, typename Duration>
auto clock_cast(const std::chrono::time_point<SourceClock, Duration>& st) auto clock_cast(const std::chrono::time_point<SourceClock, Duration>& st)
-> decltype(clock_cast_detail::cc_impl<DestClock>(st, &st)) -> decltype(clock_cast_detail::cc_impl<DestClock>(st, &st))
{ {
return clock_cast_detail::cc_impl<DestClock>(st, &st); return clock_cast_detail::cc_impl<DestClock>(st, &st);
} }
// Deprecated API // Deprecated API

View File

@ -39,7 +39,7 @@ struct mil_clock
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<std::chrono::system_clock, std::common_type_t<Duration, date::days>> std::chrono::time_point<std::chrono::system_clock, std::common_type_t<Duration, date::days>>
to_sys(std::chrono::time_point<mil_clock, Duration> const& tp) to_sys(std::chrono::time_point<mil_clock, Duration> const& tp)
{ {
++conversions; ++conversions;
@ -66,7 +66,7 @@ struct mil_clock
date::sys_days const mil_clock::epoch; date::sys_days const mil_clock::epoch;
// traits example // traits example
struct s2s_clock struct s2s_clock
{ {
using duration = std::chrono::system_clock::duration; using duration = std::chrono::system_clock::duration;
using rep = duration::rep; using rep = duration::rep;
@ -75,7 +75,7 @@ struct s2s_clock
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<std::chrono::system_clock, Duration> std::chrono::time_point<std::chrono::system_clock, Duration>
to_sys(std::chrono::time_point<s2s_clock, Duration> const& tp) to_sys(std::chrono::time_point<s2s_clock, Duration> const& tp)
{ {
++conversions; ++conversions;
@ -84,7 +84,7 @@ struct s2s_clock
template<typename Duration> template<typename Duration>
static static
std::chrono::time_point<s2s_clock, Duration> std::chrono::time_point<s2s_clock, Duration>
from_sys(std::chrono::time_point<std::chrono::system_clock, Duration> const& tp) from_sys(std::chrono::time_point<std::chrono::system_clock, Duration> const& tp)
{ {
++conversions; ++conversions;
@ -100,7 +100,7 @@ struct s2s_clock
namespace date namespace date
{ {
template<> template<>
struct clock_time_conversion<s2s_clock, mil_clock> struct clock_time_conversion<mil_clock, s2s_clock>
{ {
template<typename Duration> template<typename Duration>
std::chrono::time_point<mil_clock, std::common_type_t<Duration, date::days>> std::chrono::time_point<mil_clock, std::common_type_t<Duration, date::days>>
@ -123,7 +123,7 @@ main()
{ {
sys_days st(1997_y/dec/12); sys_days st(1997_y/dec/12);
auto mt = mil_clock::from_sys(st); auto mt = mil_clock::from_sys(st);
assert(clock_cast<mil_clock>(mt) == mt); assert(clock_cast<mil_clock>(mt) == mt);
} }
@ -133,7 +133,7 @@ main()
auto mt = mil_clock::from_sys(st); auto mt = mil_clock::from_sys(st);
assert(clock_cast<mil_clock>(st) == mt); assert(clock_cast<mil_clock>(st) == mt);
assert(clock_cast<sys_clock>(mt) == st); assert(clock_cast<sys_clock>(mt) == st);
} }
// mil <-> utc // mil <-> utc
@ -143,7 +143,7 @@ main()
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);
assert(clock_cast<mil_clock>(ut) == mt); assert(clock_cast<mil_clock>(ut) == mt);
assert(clock_cast<utc_clock>(mt) == ut); assert(clock_cast<utc_clock>(mt) == ut);
} }
// mil <-> tai // mil <-> tai
@ -179,7 +179,7 @@ main()
assert(clock_cast<mil_clock>(s2t) == mt); assert(clock_cast<mil_clock>(s2t) == mt);
assert(conversions == 1); assert(conversions == 1);
//uses sys_clock //uses sys_clock
conversions = 0; conversions = 0;
assert(clock_cast<s2s_clock>(mt) == s2t); assert(clock_cast<s2s_clock>(mt) == s2t);
assert(conversions == 2); assert(conversions == 2);

View File

@ -34,7 +34,7 @@ main()
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);
assert(to_utc_time(st) == ut); assert(to_utc_time(st) == ut);
assert(to_sys_time(ut) == st); assert(to_sys_time(ut) == st);
} }
// tai <-> utc // tai <-> utc
@ -77,7 +77,7 @@ main()
assert(to_sys_time(gt) == st); assert(to_sys_time(gt) == st);
} }
// tai <-> gps // tai <-> gps
{ {
sys_days st(1997_y/dec/12); sys_days st(1997_y/dec/12);
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);

View File

@ -25,7 +25,7 @@
#include <cassert> #include <cassert>
template<typename SourceClock, typename DestClock, typename = void> template<typename SourceClock, typename DestClock, typename = void>
struct is_clock_castable struct is_clock_castable
: std::false_type : std::false_type
{}; {};
@ -36,7 +36,7 @@ struct is_clock_castable<SourceClock, DestClock, decltype(date::clock_cast<DestC
//Clock based on steady clock, not related to wall time (sys_clock/utc_clock) //Clock based on steady clock, not related to wall time (sys_clock/utc_clock)
struct steady_based_clock struct steady_based_clock
{ {
using duration = std::chrono::steady_clock::duration; using duration = std::chrono::steady_clock::duration;
using rep = duration::rep; using rep = duration::rep;
@ -54,7 +54,7 @@ struct steady_based_clock
namespace date namespace date
{ {
template<> template<>
struct clock_time_conversion<steady_based_clock, std::chrono::steady_clock> struct clock_time_conversion<std::chrono::steady_clock, steady_based_clock>
{ {
template<typename Duration> template<typename Duration>
std::chrono::time_point<std::chrono::steady_clock, Duration> std::chrono::time_point<std::chrono::steady_clock, Duration>
@ -66,7 +66,7 @@ namespace date
}; };
template<> template<>
struct clock_time_conversion<std::chrono::steady_clock, steady_based_clock> struct clock_time_conversion<steady_based_clock, std::chrono::steady_clock>
{ {
template<typename Duration> template<typename Duration>
std::chrono::time_point<steady_based_clock, Duration> std::chrono::time_point<steady_based_clock, Duration>
@ -78,7 +78,7 @@ namespace date
}; };
} }
//Ambigous clocks both providing to/from_sys and to/from_utc //Ambigous clocks both providing to/from_sys and to/from_utc
//They are mock_ups just returning zero time_point //They are mock_ups just returning zero time_point
struct amb1_clock struct amb1_clock
{ {
@ -87,7 +87,7 @@ struct amb1_clock
using period = duration::period; using period = duration::period;
using time_point = std::chrono::time_point<amb1_clock>; using time_point = std::chrono::time_point<amb1_clock>;
static time_point now() static time_point now()
{ {
return {}; return {};
} }
@ -132,7 +132,7 @@ struct amb2_clock
using period = duration::period; using period = duration::period;
using time_point = std::chrono::time_point<amb2_clock>; using time_point = std::chrono::time_point<amb2_clock>;
static time_point now() static time_point now()
{ {
return {}; return {};
} }
@ -174,7 +174,7 @@ namespace date
{ {
//Disambiguates that sys_clock is preffered //Disambiguates that sys_clock is preffered
template<> template<>
struct clock_time_conversion<amb2_clock, amb1_clock> struct clock_time_conversion<amb1_clock, amb2_clock>
{ {
template<typename Duration> template<typename Duration>
std::chrono::time_point<amb1_clock, Duration> std::chrono::time_point<amb1_clock, Duration>
@ -214,7 +214,7 @@ main()
{ {
auto s1 = steady_clock::time_point(steady_clock::duration(200)); auto s1 = steady_clock::time_point(steady_clock::duration(200));
auto s2 = steady_based_clock::time_point(steady_based_clock::duration(200)); auto s2 = steady_based_clock::time_point(steady_based_clock::duration(200));
assert(clock_cast<steady_based_clock>(s1) == s2); assert(clock_cast<steady_based_clock>(s1) == s2);
assert(clock_cast<steady_clock>(s2) == s1); assert(clock_cast<steady_clock>(s2) == s1);
} }

View File

@ -34,7 +34,7 @@ main()
sys_days st(1997_y/dec/12); sys_days st(1997_y/dec/12);
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);
auto tt = tai_clock::from_utc(ut); auto tt = tai_clock::from_utc(ut);
assert(clock_cast<sys_clock>(st) == st); assert(clock_cast<sys_clock>(st) == st);
assert(clock_cast<utc_clock>(ut) == ut); assert(clock_cast<utc_clock>(ut) == ut);
assert(clock_cast<tai_clock>(tt) == tt); assert(clock_cast<tai_clock>(tt) == tt);
@ -46,7 +46,7 @@ main()
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);
assert(clock_cast<utc_clock>(st) == ut); assert(clock_cast<utc_clock>(st) == ut);
assert(clock_cast<sys_clock>(ut) == st); assert(clock_cast<sys_clock>(ut) == st);
} }
// tai <-> utc // tai <-> utc
@ -89,7 +89,7 @@ main()
assert(clock_cast<sys_clock>(gt) == st); assert(clock_cast<sys_clock>(gt) == st);
} }
// tai <-> gps // tai <-> gps
{ {
sys_days st(1997_y/dec/12); sys_days st(1997_y/dec/12);
auto ut = utc_clock::from_sys(st); auto ut = utc_clock::from_sys(st);

View File

@ -22,7 +22,7 @@
#include "tz.h" #include "tz.h"
struct bad_clock struct bad_clock
{ {
using duration = std::chrono::system_clock::duration; using duration = std::chrono::system_clock::duration;
using rep = duration::rep; using rep = duration::rep;
@ -31,7 +31,7 @@ struct bad_clock
template<typename Duration> template<typename Duration>
static static
int int
to_sys(std::chrono::time_point<bad_clock, Duration> const& tp) to_sys(std::chrono::time_point<bad_clock, Duration> const& tp)
{ {
return tp.time_since_epoch().count(); return tp.time_since_epoch().count();

View File

@ -22,7 +22,7 @@
#include "tz.h" #include "tz.h"
struct bad_clock struct bad_clock
{ {
using duration = std::chrono::system_clock::duration; using duration = std::chrono::system_clock::duration;
using rep = duration::rep; using rep = duration::rep;

View File

@ -22,7 +22,7 @@
#include "tz.h" #include "tz.h"
struct bad_clock struct bad_clock
{ {
using duration = std::chrono::system_clock::duration; using duration = std::chrono::system_clock::duration;
using rep = duration::rep; using rep = duration::rep;
@ -31,7 +31,7 @@ struct bad_clock
template<typename Duration> template<typename Duration>
static static
date::utc_time<Duration> date::utc_time<Duration>
to_sys(std::chrono::time_point<bad_clock, Duration> const& tp) to_sys(std::chrono::time_point<bad_clock, Duration> const& tp)
{ {
return utc_time<Duration>(tp.time_since_epoch()); return utc_time<Duration>(tp.time_since_epoch());