Where are some implementations in <type_traits> header file?

Viewed 74

I saw some implementation in <type_traits> header file, but there are some implementations that I could not find, like this:

// STRUCT TEMPLATE is_class
template <class _Ty>
struct is_class : bool_constant<__is_class(_Ty)> {}; // determine whether _Ty is a class

template <class _Ty>
_INLINE_VAR constexpr bool is_class_v = __is_class(_Ty);

I would like to know the implementation of __is_class. Does somebody know where the implementation is? I use the IDE named visual studio 2019.

1 Answers

These symbols refer to reserved, built-in tokens that are recognized and evaluated by the compiler itself. The compiler knows what __is_class means, evaluates it for the given type, and then uses the results of the evaluation.

It just so happens that gcc nicely documents its built-in symbols here (this is for gcc 10.2, other versions of gcc have pretty much the same page). EDIT: here's the same page for VS -- pretty much the same thing, from the looks of it.

On that page, somewhere you will happen to find your __is_class function defined, for gcc. Other compilers tend to make things work the same way, perhaps varying only in the names of the symbols themselves.

To summarize, you won't find __is_class, and others, formally defined in any header file. These functions, classes, et. al. are baked into the compiler itself.

Related