如果我想要一个具有可选成员的类,则使用模板专门化:struct X { void print() { cout << "t is " << t <一个可能的解决方案可能是像这样使用std::conditional:struct X {
conditional_t<is_void_v<T1>) cout <&
C++允许被调用者无论如何被声明为constexpr,只要至少有一个可能的实例化生成一个constexpr。constexpr, but compiles anywayif constexpr(foo<short>()) { /* do something */ }; // works
if constexpr(