https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #7 from Kan Liu <kan.liu.229 at gmail dot com> ---
(In reply to emsr from comment #6)
> Something like parse_number was in the original doc as an implementation
> example.  The idea was to select the smallest integral type that could
> accommodate the number string with.  This is done with _Select_int. 
> _Select_type picks the most space-efficient duration ratio type using
> _Select_int.

Yeah, but it only helps saving space when compiling time for now. For now
implementation, _Select_type takes the default chrono::hour (and other time
units), which uses *int64_t* as its underlying representation. So, it doesn't
save space I think.

Take *ms* as example
Implementation now:

    template <char... _Digits>
      constexpr typename
      __select_type::_Select_type<__select_int::_Select_int<_Digits...>::value,
                             chrono::milliseconds>::type
      operator""ms()
      {
        return __select_type::_Select_type<
                          __select_int::_Select_int<_Digits...>::value,
                          chrono::milliseconds>::value;
      }

space-efficient version (maybe), get the type from _Select_int:

template <char... _Digits>
constexpr typename
chrono::duration<decltype(__select_int::_Select_int<_Digits...>::value), milli>
operator""_ms()
{
    typedef typename __select_int::_Select_int<_Digits...> __selected;
    typedef typename chrono::duration<decltype(__selected::value), milli>
__duration_type;
    return __duration_type {__selected::value};
}

Reply via email to