隨着non-type template arguments with auto即將到來的C++ 17的功能,纔有可能以這樣的方式來實現std::function
爲能放,例如,下面的功能:具有自動功能的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
對象約束功能類型,他們接受?
(目前,海合會我們得到了error: 'auto' parameter not permitted in this context
)
假如存在這樣的事情,你會如何調用'std :: function'? –
@ n.m .:非常非常小心。 –
@LightnessRacesinOrbit,而不是通常馬虎的預先C++ 17函數的調用? –