【发布时间】:2020-05-30 22:31:40
【问题描述】:
我的函数声明和实现。 它接受可变数量的参数
template <typename... ParamType,
typename = typename std::void_t<std::enable_if_t<std::is_same_v<ParamType, std::string> ||
std::is_floating_point_v<ParamType> ||
std::is_integral_v<ParamType>>...>>
static inline void Log(const ParamType &... args)
{
//Implementation
}
我需要添加对 cstrings(char *, const char *) 和字符串文字的支持。
Console::Log("Non std::string literal"); //ERROR (const char [24])
Console::Log("hola %s %s %d %s"s,"helloWorld"s,"Joma"s,1, 1990); //OK
Console::Log<String, String, String,int, int>("hola %s %s %d %s"s,"helloWorld"s,"Joma"s,1, 1990); //OK
【问题讨论】:
-
只需将
std::is_same_v<std::decay_t<ParamType>, char const *>等添加到析取中即可。 -
错误 std::is_same_v
不满足。 -
那是“等”:您还需要与
char *相同的表达式。
标签: c++ visual-c++ c++17