is anyone aware of generalized transform, for_each? - c++

This is a discussion on is anyone aware of generalized transform, for_each? - c++ ; hi, is anyone aware of a library that generalizes transform, for_each? e.g. transform( vec1.begin(), vec1.end(), vec2.begin(), vec3.begin(), vec4.begin(), back_inserter(vec5), op )//where op is a 4-ary function...

+ Reply to Thread
Results 1 to 6 of 6

is anyone aware of generalized transform, for_each?

  1. Default is anyone aware of generalized transform, for_each?

    hi,

    is anyone aware of a library that generalizes transform, for_each?
    e.g.

    transform(
    vec1.begin(),
    vec1.end(),
    vec2.begin(),
    vec3.begin(),
    vec4.begin(),
    back_inserter(vec5),
    op
    )//where op is a 4-ary function


  2. Default Re: is anyone aware of generalized transform, for_each?

    er wrote:
    > hi,
    >
    > is anyone aware of a library that generalizes transform, for_each?
    > e.g.
    >
    > transform(
    > vec1.begin(),
    > vec1.end(),
    > vec2.begin(),
    > vec3.begin(),
    > vec4.begin(),
    > back_inserter(vec5),
    > op
    > )//where op is a 4-ary function
    >


    I've just written one,

    template <class II, class OI, class F4>
    OI transform(II first, II last, II first2, II first3, II first4, OI
    dest, F4 func)
    {
    while (first != last)
    {
    *dest = func(*first, *first2, *first3, *first4);
    ++first;
    ++first2;
    ++first3;
    ++first4;
    ++dest;
    }
    return dest;
    }

    That will be $8000 please.

    john

  3. Default Re: is anyone aware of generalized transform, for_each?

    John Harrison wrote:
    > er wrote:
    >> hi,
    >>
    >> is anyone aware of a library that generalizes transform, for_each?
    >> e.g.
    >>
    >> transform(
    >> vec1.begin(),
    >> vec1.end(),
    >> vec2.begin(),
    >> vec3.begin(),
    >> vec4.begin(),
    >> back_inserter(vec5),
    >> op
    >> )//where op is a 4-ary function
    >>

    >
    > I've just written one,
    >
    > template <class II, class OI, class F4>
    > OI transform(II first, II last, II first2, II first3, II first4, OI
    > dest, F4 func)


    template <typename II1, typename II2, typename II3, typename II4,
    typename OI, typename F4>
    OI transform(II1 first, II1 last, II2 first2, II3 first3, II4 first4,
    OI dest, F4 func)

    > {
    > while (first != last)
    > {
    > *dest = func(*first, *first2, *first3, *first4);
    > ++first;
    > ++first2;
    > ++first3;
    > ++first4;
    > ++dest;
    > }
    > return dest;
    > }
    >


    Which allows for merging of different iterator types (list, vector,
    set...) as well as different types for the values (int, float, double...)



  4. Default Re: is anyone aware of generalized transform, for_each?

    On Sep 27, 12:13 pm, red floyd <no.s...@here.dude> wrote:
    > John Harrison wrote:
    > > er wrote:
    > >> hi,

    >
    > >> is anyone aware of a library that generalizes transform, for_each?
    > >> e.g.

    >
    > >> transform(
    > >> vec1.begin(),
    > >> vec1.end(),
    > >> vec2.begin(),
    > >> vec3.begin(),
    > >> vec4.begin(),
    > >> back_inserter(vec5),
    > >> op
    > >> )//where op is a 4-ary function

    >
    > > I've just written one,

    >
    > > template <class II, class OI, class F4>
    > > OI transform(II first, II last, II first2, II first3, II first4, OI
    > > dest, F4 func)

    >
    > template <typename II1, typename II2, typename II3, typename II4,
    > typename OI, typename F4>
    > OI transform(II1 first, II1 last, II2 first2, II3 first3, II4 first4,
    > OI dest, F4 func)
    >
    > > {
    > > while (first != last)
    > > {
    > > *dest = func(*first, *first2, *first3, *first4);
    > > ++first;
    > > ++first2;
    > > ++first3;
    > > ++first4;
    > > ++dest;
    > > }
    > > return dest;
    > > }

    >
    > Which allows for merging of different iterator types (list, vector,
    > set...) as well as different types for the values (int, float, double...)


    yes, thank you both, but this is generalized in type, not in
    dimension. i should have made that clear in the first post, and
    replace 4 by an arbitrary N. i'm aware that this is no trivial
    task...hence my posting here.




  5. Default Re: is anyone aware of generalized transform, for_each?


    "er" <erwann.rogard@gmail.com> wrote in message
    news:1190859195.633687.264720@n39g2000hsh.googlegroups.com...
    > hi,
    >
    > is anyone aware of a library that generalizes transform, for_each?
    > e.g.
    >
    > transform(
    > vec1.begin(),
    > vec1.end(),
    > vec2.begin(),
    > vec3.begin(),
    > vec4.begin(),
    > back_inserter(vec5),
    > op
    > )//where op is a 4-ary function
    >


    See http://www.boost.org/libs/iterator/d..._iterator.html. Quote:

    std::vector<double>::const_iterator beg1 = vect_of_doubles.begin();
    std::vector<double>::const_iterator end1 = vect_of_doubles.end();
    std::vector<int>::const_iterator beg2 = vect_of_ints.begin();
    std::vector<int>::const_iterator end2 = vect_of_ints.end();

    std::for_each(beg1, end1, func_0());
    std::for_each(beg2, end2, func_1());
    These two iterations can now be replaced with a single one as follows:

    std::for_each(
    boost::make_zip_iterator(
    boost::make_tuple(beg1, beg2)
    ),
    boost::make_zip_iterator(
    boost::make_tuple(end1, end2)
    ),
    zip_func()
    );
    struct zip_func :
    public std::unary_function<const boost::tuple<const double&, const int&>&,
    void>
    {
    void operator()(const boost::tuple<const double&, const int&>& t) const
    {
    m_f0(t.get<0>());
    m_f1(t.get<1>());
    }

    private:
    func_0 m_f0;
    func_1 m_f1;
    };
    Jeff Flinn



  6. Default Re: is anyone aware of generalized transform, for_each?

    On Sep 27, 7:59 pm, "Jeff F" <norepl...@please.com> wrote:
    > "er" <erwann.rog...@gmail.com> wrote in message
    >
    > news:1190859195.633687.264720@n39g2000hsh.googlegroups.com...
    >
    > > hi,

    >
    > > is anyone aware of a library that generalizes transform, for_each?
    > > e.g.

    >
    > > transform(
    > > vec1.begin(),
    > > vec1.end(),
    > > vec2.begin(),
    > > vec3.begin(),
    > > vec4.begin(),
    > > back_inserter(vec5),
    > > op
    > > )//where op is a 4-ary function

    >
    > Seehttp://www.boost.org/libs/iterator/doc/zip_iterator.html. Quote:
    >
    > std::vector<double>::const_iterator beg1 = vect_of_doubles.begin();
    > std::vector<double>::const_iterator end1 = vect_of_doubles.end();
    > std::vector<int>::const_iterator beg2 = vect_of_ints.begin();
    > std::vector<int>::const_iterator end2 = vect_of_ints.end();
    >
    > std::for_each(beg1, end1, func_0());
    > std::for_each(beg2, end2, func_1());
    > These two iterations can now be replaced with a single one as follows:
    >
    > std::for_each(
    > boost::make_zip_iterator(
    > boost::make_tuple(beg1, beg2)
    > ),
    > boost::make_zip_iterator(
    > boost::make_tuple(end1, end2)
    > ),
    > zip_func()
    > );
    > struct zip_func :
    > public std::unary_function<const boost::tuple<const double&, const int&>&,
    > void>
    > {
    > void operator()(const boost::tuple<const double&, const int&>& t) const
    > {
    > m_f0(t.get<0>());
    > m_f1(t.get<1>());
    > }
    >
    > private:
    > func_0 m_f0;
    > func_1 m_f1;};
    >
    > Jeff Flinn


    thanks!


+ Reply to Thread

Similar Threads

  1. std::for_each + break
    By Application Development in forum c++
    Replies: 38
    Last Post: 11-26-2007, 05:32 AM
  2. Question about using for_each
    By Application Development in forum c++
    Replies: 3
    Last Post: 07-11-2007, 09:20 PM
  3. generalized STL set/map
    By Application Development in forum c++
    Replies: 5
    Last Post: 04-24-2007, 07:26 AM
  4. Why no simple for_each?
    By Application Development in forum c++
    Replies: 17
    Last Post: 12-18-2006, 07:34 PM
  5. for_each and a two-dimensional vector ..
    By Application Development in forum c++
    Replies: 2
    Last Post: 10-12-2006, 12:33 PM