is it ok to specialize std::numeric_limits for user-defined number-like classes?

前端 未结 3 432
猫巷女王i
猫巷女王i 2020-12-03 13:18

The documentation of std::numeric_limits says it should not be specialized for non-fundamental types. What about number-like user-defined types? If I

3条回答
  •  囚心锁ツ
    2020-12-03 13:59

    You may not specialize std::numeric_limits for a user-defined type. A user defined type is not an arithmetic type. There is clear written in the C++ Standard that

    1 The numeric_limits class template provides a C++ program with information about various properties of the implementation’s representation of the arithmetic types.

    and for example

    4 Non-arithmetic standard types, such as complex (26.4.2), shall not have specializations.

提交回复
热议问题