passing a transform as a function parameter?

Discussion in 'C++' started by Steven T. Hatton, Aug 13, 2004.

  1. If I do:

    typedef vector<size_t> v_T;

    pair<v_T, v_T> b_T;

    b_T bounds(v_T(n), v_T(n)); // if that doesn't work
    // std::make_pair(v_T(n), v_T(n));
    b_T diff_v(n);
    void populate_bounds(&bounds); // all bounds.first <= bounds.second

    If I then:

    transform(bounds.first.begin(),
    bounds.first.end(),
    bounds.second.begin(),
    diff_v.begin(),
    minus<size_t>());

    diff_t should get filled with

    diff_v == bounds.second - bounds.first

    I can then pass diff_v to a function which takes a const &v_T argument. Is
    there a way to iliminate diff_v, and simply feed the transform to the
    function taking &v_T?

    --
    STH
    Hatton's Law: "There is only One inviolable Law"
    KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
    Mozilla: http://www.mozilla.org
    Steven T. Hatton, Aug 13, 2004
    #1
    1. Advertising

  2. Steven T. Hatton wrote:
    > If I do:
    >
    > typedef vector<size_t> v_T;
    >
    > pair<v_T, v_T> b_T;


    Did you mean

    typedef std::pair<v_T,v_T> b_T;

    ?

    >
    > b_T bounds(v_T(n), v_T(n)); // if that doesn't work
    > // std::make_pair(v_T(n), v_T(n));
    > b_T diff_v(n);


    I don't think you can initialise a pair this way. Did you mean

    v_T diff_v(n);

    ??

    > void populate_bounds(&bounds); // all bounds.first <= bounds.second
    >
    > If I then:
    >
    > transform(bounds.first.begin(),
    > bounds.first.end(),
    > bounds.second.begin(),
    > diff_v.begin(),
    > minus<size_t>());
    >
    > diff_t should get filled with
    >
    > diff_v == bounds.second - bounds.first
    >
    > I can then pass diff_v to a function which takes a const &v_T argument. Is
    > there a way to iliminate diff_v, and simply feed the transform to the
    > function taking &v_T?


    Since you didn't clarify how v_T contains the bounds, I would have to dive
    into a pool of assumptions, and it's usually wrong. Perhaps you could be
    more specific. Otherwise, the generic answer is, "yes, you can do that,
    you only need to correctly define the iterator and the functor".

    Victor
    Victor Bazarov, Aug 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    603
    John Carson
    Jul 30, 2003
  2. Alex Vinokur
    Replies:
    5
    Views:
    608
    Alex Vinokur
    Nov 4, 2003
  3. Azdo
    Replies:
    2
    Views:
    433
  4. Mister B
    Replies:
    8
    Views:
    548
    Nick Keighley
    Aug 26, 2010
  5. AzamSharp
    Replies:
    2
    Views:
    174
Loading...

Share This Page