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

Pages: 1-

cleaner solution

Name: Anonymous 2009-01-24 17:45

when coming back to C++ after coding quite a bit haskell and python I felt a need for a map function.

my first go at it ended in this:

template <typename O, typename I, typename func_p>
std::list<O> & map(func_p func, const std::list<I> & in, std::list<O> & out) {
    for(typename std::list<I>::const_iterator it = in.begin(); it != in.end(); ++it) {
        out.push_back(func(*it));
    }
    return out;
}


it's not really as good as I want it to be (forced std::list etc) but the only thing google found was weird implementation with some weird recursive-template lists. anyone got a better one?

also, lul wut textboard

Name: Anonymous 2009-01-24 17:52

Name: Anonymous 2009-01-24 17:52

No exSEPPLESions.

Name: sage 2009-01-24 17:54

sage

Name: Anonymous 2009-01-24 17:56

Well, there's std::transform, which is more general.

Name: Anonymous 2009-01-24 18:02

>>5
see
>>3

Name: OP 2009-01-24 18:11

oh, guess im no googleninja after all. thanks anon.

Name: Anonymous 2010-12-24 23:50

Name: Anonymous 2011-02-03 0:24

Name: Anonymous 2011-02-18 13:50

<-- check 'em dubz

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