在计算类型后省略参数名称

Omit argument name after computed type

为什么下面的不编译

#include <type_traits>

template<class T>
void stuff(T, std::enable_if_t<std::is_trivial_v<T>, int>=0);

虽然这样

template<class T>
void stuff2(T, int=0);

计算类型时似乎需要参数名称。如果我使用 -Wunused-parameter 构建,是否有比 (void)x 技巧更好的解决方案?

实际用例:

template<class SrcType, size_t N>
explicit constexpr ShortString(SrcType const (&src)[N]
                              , std::enable_if_t<(N>=1 && (N - 1 <= npos) && sizeof(SrcType)<=sizeof(value_type)), int> x = 0);

这里有两个问题:

  1. std::is_trivial_v<T>::value 中的拼写错误 - 删除 _v::value
  2. >= in std::enable_if_t< ... >=0 以单个标记('greater than' 符号)结束。您需要用 space.
  3. 分隔 >=

GCC 对第二个问题毫无帮助:
<source>:4:64: error: template argument 2 is invalid

但 Clang 提供了更多见解:
<source>:4:62: error: a space is required between a right angle bracket and an equals sign (use '> =')