While going through some of the type traits, I was searching how does std::is_const<type_name> work. According to the definition in it is
#if __has_builtin(__is_const)
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_const : _BoolConstant<__is_const(_Tp)> { };
// ...
#else
// "normal" type trait
#endif
I know it's a compiler builtin, but was wondering on a high level as to how it's implemented?
It's implemented via an X macro that populates a map of type
llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>.From
clang/lib/Parse/ParseExpr.cpp:... and then when parsing your code, the
RevertibleTypeTraitsmap is consulted:This is internal compiler details. It'll likely look very different when looking inside another compiler's code.