Why is std::integral defined with a type_trait and not with std::numeric_limits?

740 Views Asked by At

Why is the concept std::integral defined as

template < class T > concept integral = std::is_integral_v<T>;

and not as

template < class T > concept integral = std::numeric_limits<T>::is_integer;

?

This means that the concept std::integral is restricted to "fundamental integral". For example, this is true:

std::numeric_limits<boost::multiprecision::cpp_int>::is_integer;

but this is false:

std::integral<boost::multiprecision::cpp_int>;

Is there any option to activate std::integral for user-defined types? What is missing e.g. in boost::multiprecision::cpp_int so that it does not fulfill the concept integral?

1

There are 1 best solutions below

8
Nicol Bolas On

This means that the concept "std::integral" is restricted to "fundamental integral".

Yes; that's what std::integral is for: telling you if a type is an integral type as defined by the standard.

If you want "integer type as defined by numeric_limits" or something else, you're going to need a different definition and therefore a different concept.