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

Pages: 1-

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 13:01

This is a c++ problem
Actually, C++ IS the problem.

Name: Anonymous 2009-11-02 13:02

>>1
I guess you could say you dream of cocks drifting across the blue sky.

Name: Anonymous 2009-11-02 13:03

can I do this in a easy, elegant way?
Sepples
( ≖‿≖)

Name: Anonymous 2009-11-02 13:12

(remove x sequence)

Name: Anonymous 2009-11-02 13:19

template <class typeA> struct containsValue {
    typeA value;
    containsValue(typeA val) : value(val) {}
    bool operator()(pair<typeA, typeA> subj)
    {
        return subj.first == value || subj.second == value;
    }
};
...
    v.erase(remove_if(v.begin(), v.end(), containsValue<int>(5)), v.end());

Name: Anonymous 2009-11-02 13:35

>>6
Thank you, much appreciated.

Name: Anonymous 2009-11-02 13:36

>>5
Is that the haskell I keep hearing of?

Name: Anonymous 2009-11-02 13:38

Some people, when faced with a problem, will say: ``I know, I'll use the STL!''. Now they have three problems. (The third being Sepples).

Name: Anonymous 2009-11-02 16:38


>>1:3: error: `>>' should be `> >' within a nested template argument list

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?

Name: Anonymous 2009-11-02 16:49

>>11
do you just suck dick at picking the right tool for the job?
OP is using C++

Name: Anonymous 2009-11-03 9:44

>>8
Common Lisp.

Name: Anonymous 2009-11-03 10:45

>>13
R6RS.

Name: Anonymous 2009-11-03 10:54

>>14
ROSSICKSRIS

Name: >>5 2009-11-03 11:38

>>14
Hmm, forgot they added that function to R6RS too. There are some differences between it and the CL version, such as lack of the large variety of keyword arguments.

Name: Anonymous 2010-12-06 9:18

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-01-31 20:07

<-- check em dubz

Name: Anonymous 2011-02-04 11:47

Name: Anonymous 2011-02-04 12:07

Name: Anonymous 2011-02-04 12:29

Name: Anonymous 2011-02-04 13:30

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