Я пытаюсь использовать std::result_of
на функторах. Почему я получаю эти результаты?std :: result_of на полиморфных функторах
#include <typeinfo>
struct my_logical_not {
template<typename A>
bool operator()(const A &value) const {
return !value;
}
};
struct my_passthrough {
template<typename A>
A operator()(A &value) const {
return value;
}
};
int main() {
// this prints 'b':
std::cout << typeid(typename std::result_of<my_logical_not(int)>::type).name() << std::endl;
// this does not compile:
// main.cpp:24:66: error: ‘type’ in ‘class std::result_of<my_passthrough(int)>’ does not name a type
std::cout << typeid(typename std::result_of<my_passthrough(int)>::type).name() << std::endl;
return 0;
}
'my_passthrough (INT)' означает, что вы хотите rvalue типа int в качестве аргумента, который не связывается с ссылкой на не константу lvalue –
Совет: вам не нужны «typenames» здесь –
Я вижу .. изменение my_passthrough operator() как оператора A() (const A & value) const "исправил его. Благодаря! –