C++ std::invoke\u result\u t编译时语法错误
我正在创建一个函数,它接受一个iterable(容器),它的begin和end方法返回迭代器,迭代器的解引用可以被传递的lambda修改。这听起来很复杂,但我正在尝试做一些类似Python的超级简洁的事情C++ std::invoke\u result\u t编译时语法错误,c++,iterator,C++,Iterator,我正在创建一个函数,它接受一个iterable(容器),它的begin和end方法返回迭代器,迭代器的解引用可以被传递的lambda修改。这听起来很复杂,但我正在尝试做一些类似Python的超级简洁的事情 modified_iterator = (fn(x) for x in my_iterator) 代码: 错误: In file included from /Users/adam/school/cpp/invertedindex/main.cpp:203:0: /Users/adam/sc
modified_iterator = (fn(x) for x in my_iterator)
代码:
错误:
In file included from /Users/adam/school/cpp/invertedindex/main.cpp:203:0:
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:105: error: template argument 1 is invalid
typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> operator* () const { // typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> not compiling??
^~
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:121: error: template argument 2 is invalid
typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> operator* () const { // typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> not compiling??
^~~~~
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:127: error: expected identifier before '{' token
typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> operator* () const { // typename std::invoke_result_t<Fn, typename std::invoke_result_t<typename Iterator::operator*>> not compiling??
^
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:127: error: expected unqualified-id before '{' token
In file included from /Users/adam/school/cpp/invertedindex/main.cpp:203:0:
包含在/Users/adam/school/cpp/invertedindex/main.cpp:203:0:
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:105:错误:模板参数1无效
typename std::invoke_result_t运算符*()常量{//typename std::invoke_result_t未编译??
^~
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:121:错误:模板参数2无效
typename std::invoke_result_t运算符*()常量{//typename std::invoke_result_t未编译??
^~~~~
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:127:错误:在“{”标记之前应该有标识符
typename std::invoke_result_t运算符*()常量{//typename std::invoke_result_t未编译??
^
/Users/adam/school/cpp/invertedindex/inverted_index.hpp:61:127:错误:在“{”标记之前应该有不合格的id
在/Users/adam/school/cpp/invertedindex/main.cpp:203:0中包含的文件中:
您希望类型名迭代器::运算符*
生成什么?类型?函数指针?函数指针的类型
没有名为operator*
的成员类型。可能有一个函数以这种方式命名。您的意思是将其返回类型用于馈送std::invoke\u result\t
如果是,那将是:
std::invoke_result_t<decltype(&Iterator::operator*), Iterator>
std::invoke\u result\t
但您可以通过一个简单的declval将其缩短:
decltype(*std::declval<Iterator>())
decltype(*std::declval())
您希望类型名迭代器::运算符*
生成什么?类型?函数指针?函数指针的类型
没有名为operator*
的成员类型。可能有一个函数以这种方式命名。您的意思是将其返回类型用于馈送std::invoke\u result\t
如果是,那将是:
std::invoke_result_t<decltype(&Iterator::operator*), Iterator>
std::invoke\u result\t
但您可以通过一个简单的declval将其缩短:
decltype(*std::declval<Iterator>())
decltype(*std::declval())
我在答案中修复了它,是的,显然它应该是迭代器的类成员函数操作符*
的返回类型。类型名出现在那里,因为我一直在努力使它工作。迭代器::操作符*
应该是指向函数的指针(我不太熟悉函数指针)。所以它不是一个类型,它是一个带值的指针,所以你必须做decltype
。好的,谢谢。我在答案中修复了它,是的,显然它应该是Iterator
的类成员函数操作符*
的返回类型。typename
出现在那里,因为我尝试了一切让它工作。我pectIterator::operator*
是指向函数的指针(我不太熟悉指向函数的指针)。所以它不是一个类型,它是一个带值的指针,所以您必须执行decltype
操作。好的,谢谢。
decltype(*std::declval<Iterator>())