c++ - Why is digits10 for reference to integer type 0? -
the following code:
#include <iostream> #include <limits> #include <cstdint>  int main()  {     std::cout << std::numeric_limits<std::uint64_t>::digits10 << "\n"                << std::numeric_limits<std::uint64_t&>::digits10 << "\n"; }   outputs
19
0
i expect std::uint64_t& have same value std::uint64_t: there reason discrepancy?
18.3.2.1/2:
specializations shall provided each arithmetic type, both floating point , integer, including bool. member is_specialized shall true such specializations of numeric_limits.
so know specializations exist for these non-reference types. 18.3.2.3/1:
the default numeric_limits template shall have members, 0 or false values.
i suspect done way because can static_assert on is_specialized force compile error, there possibly template application 0 ok default value 1 or more of limits. if want able test references run through std::remove_reference.
i'm not sure if it's legal specialize numeric_limits own types. standard in 18.3.2.1/4 says:
non-arithmetic standard types, such complex (26.4.2), shall not have specializations.
i read qute "the standard not provide specializations non-arithmetic standard libray types, it's legal specialize user type". read totally forbidding non-provided specializations.
Comments
Post a Comment