呼び出し可能なオブジェクト (関数)a
と引数(または一連の引数) が与えられた場合、複数のシグネチャでオーバーロードされていることを考慮して、b
返される型を推測したいと思います。f
f
私の多くの試みの1つは
#include <iostream>
#include <cstdint>
#include <string>
#include <functional>
#include <utility>
#include <typeinfo>
int foo(uint32_t a) { return ((a + 0) * 2); }
bool foo(std::string a) { return (a.empty()); }
/*template <typename A, typename B> auto bar(A a, B b) -> decltype(a(b)) {
return (a(b));
}*/
/*template <typename A, typename B> decltype(std::declval<a(b)>()) bar(A a, B b)
{
return (a(b));
}*/
template <typename A, typename B> void bar(std::function<A(B)> a, B b) {
std::cout << a(b) << "\n";
}
int main() {
// the following 2 lines are trivial and they are working as expected
std::cout << foo(33) << "\n";
std::cout << typeid(decltype(foo(std::string("nothing")))).name() << "\n";
std::cout << bar(foo, 33) << "\n";
//std::cout << bar(foo, std::string("Heinz")) << "\n";
return (0);
}
および 2 つのテンプレート オプションがコメント アウトされ、前のコードに含まれています。
何気なく使ってdeclval result_of auto decltype
ます。
オーバーロード解決プロセスはコンパイル時にどのように機能しますか?
私がこれでクリエイティブになろうとしている理由を知りたい人がいれば、C++11 で実行可能な/きちんとした方法でカリー化を実装しようとしているということです。