I have a list and I'm using an iterator to locate an item in the list:
std::list<std::string> groupsList = { Constants::Item1, Constants::Item2, ... };
std::list<std::string>::iterator groupListItr = std::find(groupsList.begin(), groupsList.end(), group);
if ( groupListItr == grousList.end() ) {
return;
}
uint16_t groupIdx = (uint16_t)(groupListItr - groupsList.begin());
In the above find call "group" is the string to locate. I'm trying to figure out how to get the position of the found item in the list, if there is an easier way to do this please let me know, the calculation of the index results in an error when compiling:
error C2784: 'unknown-type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::_List_iterator<std::_List_val<std::_List_simple_types<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>>'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(937) : see declaration of 'std::operator -'
The solution:
uint16_t groupIdx = (uint16_t)std::distance(groupsList.begin(), groupListItr);