【发布时间】:2016-09-27 14:19:24
【问题描述】:
随着non-type template arguments with auto即将推出的C++17特性,是否有可能以能够放置例如以下函数的方式实现std::function:
bool f(int n, double d) {}
bool g(bool b, char c) {}
bool h(bool b) {}
进入自动模板化的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
等等。
换句话说,让std::function 对象受限于它们接受的函数类型?
(目前,在 GCC 上,我们会收到 error: 'auto' parameter not permitted in this context。)
【问题讨论】:
-
假设存在这样的事情,你怎么称呼
std::function<bool(auto, auto)>? -
@n.m.:非常非常小心。
-
@LightnessRacesinOrbit 而不是通常草率地调用 C++17 之前的函数?
-
@n.m.:当然!
标签: c++ templates auto c++17 std-function