例如:
if (true) try
{
// works as expected with both true and false, but is it legal?
}
catch (...)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
换句话说,将if -block放在if条件之后是否合法?
随着即将推出的带有auto的非类型模板参数的 C++ 17特性,是否可以以std::function能够放置例如以下函数的方式实现:
bool f(int n, double d) {}
bool g(bool b, char c) {}
bool h(bool b) {}
Run Code Online (Sandbox Code Playgroud)
进入自动模板化的std::function对象:
std::function<bool(auto, auto)> faa = f; // ok
std::function<bool(int, auto)> fia = f; // ok
std::function<bool(double, auto)> fda = f; // error: function type mismatch
std::function<bool(auto, auto)> gaa = g; // ok
std::function<bool(auto, auto)> haa = h; // error: function type mismatch
std::function<bool(auto)> ha = h; // ok
Run Code Online (Sandbox Code Playgroud)
等等.
换句话说,让std::function对象受限于他们接受的函数类型? …
例如:
#include <thread>
thread_local int n = 1;
void f()
{
++n; // is n initialized here for each thread or prior to entering f()?
}
int main()
{
std::thread ta(f);
std::thread tb(f);
ta.join();
tb.join();
}
Run Code Online (Sandbox Code Playgroud)
它仍然是不完全清楚,从这里为n初始化时。