我有这样的代码:unordered_set ::的remove_if():C3892:不能分配给一个变量是常量
unordered_set<AttrValue> output;
...
auto requiredType = variables.at(arg.value);
auto end = remove_if(output.begin(), output.end(),
[&](AttrValue x) {
return !matchingOutputType(requiredType, ast->getNodeType(ast->getNodeKeyAttribute(x)));
}); // queryevaluator_getcandidatelist.cpp(179)
output.erase(end);
错误是对代码的4行。所以我认为它是因为remove_if
。但最新错误?输出没有定义常量?
Error 90 error C3892: '_Next' : you cannot assign to a variable that is const c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1840
Error 109 error C3892: '_Next' : you cannot assign to a variable that is const c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm 1840
输出窗口:
3>c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(1840): error C3892: '_Next' : you cannot assign to a variable that is const
3> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(1853) : see reference to function template instantiation '_FwdIt std::_Remove_if<std::_List_unchecked_const_iterator<_Mylist>,_Pr>(_FwdIt,_FwdIt,_Pr)' being compiled
3> with
3> [
3> _FwdIt=std::_List_unchecked_const_iterator<std::_List_val<int,std::allocator<AttrValue>>>,
3> _Mylist=std::_List_val<int,std::allocator<AttrValue>>,
3> _Pr=`anonymous-namespace'::<lambda4>
3> ]
3> h:\dropbox\sch\cs3202\code\source\query\query evaluator\queryevaluator_getcandidatelist.cpp(179) : see reference to function template instantiation '_FwdIt std::remove_if<std::_List_const_iterator<_Mylist>,`anonymous-namespace'::<lambda4>>(_FwdIt,_FwdIt,_Pr)' being compiled
3> with
3> [
3> _FwdIt=std::_List_const_iterator<std::_List_val<int,std::allocator<AttrValue>>>,
3> _Mylist=std::_List_val<int,std::allocator<AttrValue>>,
3> _Pr=`anonymous-namespace'::<lambda4>
3> ]
根据http://www.cprogramming.com/c++11/c++11-auto-decltype-return-value-after-function.html'auto'有时也可以隐含地赋予常量。这是这种情况吗? –
[删除成语与std :: set失败与constness相关的错误]的可能重复(http://stackoverflow.com/questions/3792600/erase-remove-idiom-with-stdset-failing-with-constness-相关的错误) – soon