I have a list of tuples and need to remove elements from the list, something like this:
enum class test
{
mem1,
mem2,
mem3,
mem4
};
struct A
{
};
int main()
{
std::list<std::tuple<int, test, A>> tuple_list;
// fill list with random objects
for (int i = 0; i < 4; i++)
{
tuple_list.push_back(
std::forward_as_tuple(i, static_cast<test>(i), A()));
}
// now remove it
for (auto& ref : tuple_list)
{
tuple_list.remove(ref); // error C2678
}
return 0;
}
error C2678: binary '==': no operator found which takes a left-hand operand of type 'const _Ty' (or there is no acceptable conversion)
How do I remove tuple elements from the list in above example?
EDIT:
I tried following method, it compiles just fine unlike previous example but there is runtime assertion:
int main()
{
list<tuple<int, test, A>> tuple_list;
for (int i = 0; i < 4; i++)
{
tuple_list.push_back(
std::forward_as_tuple(i, static_cast<test>(i), A()));
}
for (auto iter = tuple_list.begin(); iter != tuple_list.end(); iter++)
{
tuple_list.erase(iter);
}
}
Expression: can not increment value initialized list iterator