Differences between std::is_integer and std::is_integral?

后端 未结 5 1899
粉色の甜心
粉色の甜心 2021-01-01 10:02

C++11 provides two type trait template classes: std::is_integer and std::is_integral. However, I cannot tell the differences between them.

5条回答
  •  不知归路
    2021-01-01 10:23

    std::is_integral and std::numeric_limits::is_integer are NOT the same. E.g. boost::multiprecision big ints are treated differently.

    This is from a corresponding issue:

    is_integral returns information about the nature of the type and is true only for "native" integer types, it should never be true for class types. Which is to say is_integer and is_class are mutually exclusive.

    numeric_limits on the other hand returns information on the behaviour of a type - whether it models a particular concept if you will - and so should be specialized for UDT's. Note that specializing is_integer for UDTs would break code, since is_integer implies that a lot of other things are also true like trivial move/copy/init etc.

提交回复
热议问题