Simplify implementation details of "chrono_io.h"

This commit is contained in:
Howard Hinnant 2016-10-08 15:03:33 -04:00
parent 19c83e47ed
commit f66af06870

View File

@ -381,34 +381,34 @@ msl(std::exa) noexcept
return msl(CharT{'E'}); return msl(CharT{'E'});
} }
template <class CharT, class Rep, class Period> template <class CharT, class Period>
constexpr constexpr
auto auto
get_units(const std::chrono::duration<Rep, Period>&) get_units(Period p)
{ {
return msl<CharT>(Period{}) + string_literal<CharT, 2>{"s"}; return msl<CharT>(p) + string_literal<CharT, 2>{"s"};
} }
template <class CharT, class Rep> template <class CharT>
constexpr constexpr
auto auto
get_units(const std::chrono::duration<Rep, std::ratio<1>>&) get_units(std::ratio<1>)
{ {
return string_literal<CharT, 2>{"s"}; return string_literal<CharT, 2>{"s"};
} }
template <class CharT, class Rep> template <class CharT>
constexpr constexpr
auto auto
get_units(const std::chrono::duration<Rep, std::ratio<60>>&) get_units(std::ratio<60>)
{ {
return string_literal<CharT, 4>{"min"}; return string_literal<CharT, 4>{"min"};
} }
template <class CharT, class Rep> template <class CharT>
constexpr constexpr
auto auto
get_units(const std::chrono::duration<Rep, std::ratio<3600>>&) get_units(std::ratio<3600>)
{ {
return string_literal<CharT, 2>{"h"}; return string_literal<CharT, 2>{"h"};
} }
@ -620,30 +620,30 @@ msl(std::exa) noexcept
return {'E'}; return {'E'};
} }
template <class CharT, class Rep, class Period> template <class CharT, class Period>
std::basic_string<CharT> std::basic_string<CharT>
get_units(const std::chrono::duration<Rep, Period>&) get_units(Period p)
{ {
return msl<CharT>(Period{}) + CharT{'s'}; return msl<CharT>(p) + CharT{'s'};
} }
template <class CharT, class Rep> template <class CharT>
std::basic_string<CharT> std::basic_string<CharT>
get_units(const std::chrono::duration<Rep, std::ratio<1>>&) get_units(std::ratio<1>)
{ {
return {'s'}; return {'s'};
} }
template <class CharT, class Rep> template <class CharT>
std::basic_string<CharT> std::basic_string<CharT>
get_units(const std::chrono::duration<Rep, std::ratio<60>>&) get_units(std::ratio<60>)
{ {
return {'m', 'i', 'n'}; return {'m', 'i', 'n'};
} }
template <class CharT, class Rep> template <class CharT>
std::basic_string<CharT> std::basic_string<CharT>
get_units(const std::chrono::duration<Rep, std::ratio<3600>>&) get_units(std::ratio<3600>)
{ {
return {'h'}; return {'h'};
} }
@ -660,7 +660,7 @@ operator<<(std::basic_ostream<CharT, Traits>& os,
{ {
using namespace std::chrono; using namespace std::chrono;
return os << d.count() return os << d.count()
<< detail::get_units<CharT>(duration<Rep, typename Period::type>{}); << detail::get_units<CharT>(typename Period::type{});
} }
} // namespace date } // namespace date