Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Special case of remove_if (C++)

Name: Anonymous 2009-11-02 12:54

Sup /prog/, I'm asking for a bit of help.

So I got a std::vector<std::pair<typeA , typeA>>, and I want to remove all pairs containing some typeA value 'x'.

(How) can I do this in a easy, elegant way?

I've thought about using the STL algorithm remove_if, but looking at this reference:

http://www.cplusplus.com/reference/algorithm/remove_if/

template < class ForwardIterator, class Predicate >

ForwardIterator remove_if ( ForwardIterator first, ForwardIterator last, Predicate pred )

pred
    Unary predicate taking an element in the range as argument, and returning a value indicating the falsehood (with false, or a zero value) or truth (true, or non-zero) of some condition applied to it. This can either be a pointer to a function or an object whose class overloads operator().

Seems like remove_if can't do the trick then, eh? It has to have the pair object and the reference value 'x'.

This is a c++ problem, if I didn't make it clear enough before.

Name: Anonymous 2009-11-02 16:48

>>1
I don't see why you'd use vector when you seem to want key/value functionality. map and unordered_map are designed specifically for key/value.

I'd understand if they were just a pair with no special relationship and you want duplicates, but that STILL doesn't make sense.

Is there something I'm missing or do you just suck dick at picking the right tool for the job?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List