select1st, select2nd

I've run into a use case where I'd like to use a mapped_iterator to
iterator the 1st (or 2nd) items in a sequence of std::pairs. Does
select1st/select2nd exist somewhere within LLVM or is there some
equivalent? If not, I'll add it.

                               -Dave

Is this making the resultant loop simpler? C++ without lambda's isn't very friendly to functors, what is the before/after effect of doing this?

-Chris

I believe he's referring to this:

http://www.sgi.com/tech/stl/select1st.html

I believe he's referring to this:

http://www.sgi.com/tech/stl/select1st.html

I'm familiar with it. I'm asking why it is better to use it than an explicit loop.

-Chris

Chris Lattner <clattner@apple.com> writes:

I've run into a use case where I'd like to use a mapped_iterator to
iterator the 1st (or 2nd) items in a sequence of std::pairs. Does
select1st/select2nd exist somewhere within LLVM or is there some
equivalent? If not, I'll add it.

Is this making the resultant loop simpler? C++ without lambda's isn't
very friendly to functors, what is the before/after effect of doing
this?

It's going to unify the DagInit constructors into one piece of code.
The problem now is there are two constructors. One takes a vector of
pairs and the other takes two vectors. They each make sense in their
use contexts but it results in a lot of code duplication when moving
DagInit to a uniqued pool implementation. I wanted to put the
processing code in a third function which would be called with various
types of iterators over those vectors.

                              -Dave

Scott Conger <scott.conger@gmail.com> writes:

I believe he's referring to this:

http://www.sgi.com/tech/stl/select1st.html

Right. It's in libstdc++ as an extension but that's not portable.

                        -Dave

The problem that I have with this sort of higher order metaprogramming in C++'98 is that you're trading one set of complexity for another. Please just introduce a helper function or something and duplicate the loop.

-Chris

Chris Lattner <clattner@apple.com> writes:

The problem that I have with this sort of higher order metaprogramming

Metaprogramming? This isn't template metaprogramming if that's what you
mean.

in C++'98 is that you're trading one set of complexity for another.

What's the other complexity?

                            -Dave

I'm talking about mapped iterator + select1st.

-Chris

Chris Lattner <clattner@apple.com> writes:

I'm talking about mapped iterator + select1st.

Right. It's just functional programming (mostly). Isn't this why
mapped_iterator exists?

In any event, if you really object, I guess I will write separate loops.
Seems like we're throwing away a lot of the power of C++, though.

                                -Dave