G
gelbeiche
I have a std::list and I want extend the content of
the list (append a value) only if the value not
already exist.
E.g. I can write for a std::list<int> :
A)
if ( std::find(l.begin(),l.end(), 3) == l.end() )
l.insert(l.end(),3);
or
B)
if ( std::find(l.begin(),l.end(), 3) == l.end() )
l.push_back(3);
I have two questions:
1) Is there a better respectively shorter way to
express this ?
2) Which of both inserts (A or B) is the better one ?
the list (append a value) only if the value not
already exist.
E.g. I can write for a std::list<int> :
A)
if ( std::find(l.begin(),l.end(), 3) == l.end() )
l.insert(l.end(),3);
or
B)
if ( std::find(l.begin(),l.end(), 3) == l.end() )
l.push_back(3);
I have two questions:
1) Is there a better respectively shorter way to
express this ?
2) Which of both inserts (A or B) is the better one ?