C++11 constexpr 和 typeid(type)

Mar*_*rry 6 compilation c++11

有没有办法,如何typeid使用 constexpr 在编译时进入变量?

这不起作用,因为std::type_index没有 constexpr ctor

constexpr std::type_index i = typeid(double);
Run Code Online (Sandbox Code Playgroud)

Rei*_*ica 2

在某种程度上,有:

constexpr const std::type_info &i = typeid(double);
Run Code Online (Sandbox Code Playgroud)

您必须记住typeid返回的是 type const std::type_info &,而不是 a std::type_index