【发布时间】:2019-10-02 18:17:33
【问题描述】:
为什么下面的不能编译
#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);
【问题讨论】: