我很难弄清楚这个示例代码中导致替换失败的原因:
bool f(int a, int b, float c)
{
printf("%d %d %f", a, b, c);
return true;
}
template <typename ...Params>
void call1(Params... params, std::function<bool(Params...)> func)
{
func(params...);
}
template <typename ...Params>
void call2(std::function<bool(Params...)> func)
{
}
Run Code Online (Sandbox Code Playgroud)
主要的地方:
call1<int, int, float>(3, 4, 5.5, f); // Ok.
call2<int, int, float>(f); // Substitution failure.
Run Code Online (Sandbox Code Playgroud)
编译器说:
template argument deduction/substitution failed: mismatched types 'std::function<bool(Params ...)>' and 'bool (*)(int, int, float)'
call2<int, int, float>(f);
^
Run Code Online (Sandbox Code Playgroud)
令我感到困惑的是call1有效,而call2没有.有小费吗?=)
有没有人知道一种方法来评估字符串,以便如果它(或它定义的函数)产生错误,堆栈跟踪中显示的行号和列号将偏移预先指定的数量?或者,假设我想将一个长源字符串分解为块并单独评估它们,但仍然得到堆栈跟踪,看起来好像整个字符串都是一次性评估的.有没有办法实现这个效果,除了使用空行和列?(我需要一个基于浏览器的解决方案,最好是跨浏览器,但我可以满足至少一个主流浏览器的功能.)