これをコンパイルしようとすると驚いたことにラムダ関数のパラメータがstd::string
に解決され、 test
に電話するとstd::string
をint
またはWidget
に変換する方法がわかりません。std :: functionとgeneric lambdasで関数のオーバーロードが発生しました:std :: stringがintより優先されました
しかし、コンパイラは最初のものは成功するだろうというとき、代わりに最初のものの第二invok
機能を選びだした理由私は疑問に思う:
#include <string>
#include <functional>
struct Widget {};
bool test(int);
bool test(Widget);
void invok(std::function<bool(int)>); // #1
void invok(std::function<bool(std::string)>); // #2
int main()
{
// error: unresolved overloaded function type
// invok(test);
// still error: no known conversion from std::string to
// int or Widget
invok([](auto&& x) {
return test(std::forward<decltype(x)>(x));
});
}
を例にa C++ proposalからコピーされたこと。
ああ、SFINAE-非友好的な一般的なラムダ。 –
私はこの質問を承認します。 – Barry