0
我想使用result_of的情況下,當Callable返回模板類型並獲得以下錯誤(鏗鏘聲++)。我還包括一個簡單的例子,一切正常。當返回值是模板類型時如何使用std :: result_of?
錯誤:
main.cpp:22:50: note: candidate template ignored: could not match '<type-parameter-0-1>' against 'std::__1::shared_ptr<int> (*)()'
typename std::result_of<FunctionType<T>()>::type submit(FunctionType<T> f) {
代碼:
int f() {
int x = 1;
return x;
}
template<typename T>
std::shared_ptr<T> g() {
std::shared_ptr<T> x;
return x;
}
template <template<typename> class FunctionType, typename T>
typename std::result_of<FunctionType<T>()>::type submit(FunctionType<T> f) {
using result_type = typename std::result_of<FunctionType<T>()>::type;
result_type x;
return x;
}
template<typename FunctionType>
typename std::result_of<FunctionType()>::type submit2(FunctionType f) {
using result_type = typename std::result_of<FunctionType()>::type;
result_type x;
return x;
}
int main()
{
submit(g<int>); // error
submit2(f); // ok
return 0;
}
謝謝!我想我現在明白了。 –