Use of lower_bound

Discussion in 'C++' started by Jim West, Oct 15, 2004.

  1. Jim West

    Jim West Guest

    The following code does what I want it to do on two different compilers
    (g++ and Intel icc under Linux), but I'm not sure if it is undefined
    and just happens to work:


    class A {
    public:
    int i;
    };

    bool comp_A_i (const A &a, int i) {
    return a.i < i;
    }

    int main( ) {
    std::vector<A> v(6);
    int i;
    std::vector<A>::iterator pos
    = lower_bound(v.begin(), v.end(), i, comp_A_i);
    }

    Is the function comp_A_i properly defined having two different
    argument types?
    Jim West, Oct 15, 2004
    #1
    1. Advertising

  2. In article <>,
    Jim West <> wrote:

    > The following code does what I want it to do on two different compilers
    > (g++ and Intel icc under Linux), but I'm not sure if it is undefined
    > and just happens to work:
    >
    >
    > class A {
    > public:
    > int i;
    > };
    >
    > bool comp_A_i (const A &a, int i) {
    > return a.i < i;
    > }
    >
    > int main( ) {
    > std::vector<A> v(6);
    > int i;
    > std::vector<A>::iterator pos
    > = lower_bound(v.begin(), v.end(), i, comp_A_i);
    > }
    >
    > Is the function comp_A_i properly defined having two different
    > argument types?


    Strictly speaking, this is not guaranteed to work in C++03. But I
    wouldn't sweat it. Every major vendor has agreed that it should work,
    and also agreed to revise the next version of the standard to enforce
    that decision:

    http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#270

    So from a practical standpoint, you're good to go. And it will be made
    official some time down the road.

    -Howard
    Howard Hinnant, Oct 15, 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. Alex Vinokur

    lower_bound

    Alex Vinokur, Jul 30, 2003, in forum: C++
    Replies:
    4
    Views:
    575
    Sam Holden
    Jul 31, 2003
  2. Jaap
    Replies:
    3
    Views:
    1,743
  3. Replies:
    3
    Views:
    321
  4. Fred Zwarts
    Replies:
    5
    Views:
    1,542
    Andrew Koenig
    Apr 23, 2006
  5. Diego Martins

    stl map, lower_bound and upper_bound

    Diego Martins, Aug 14, 2006, in forum: C++
    Replies:
    3
    Views:
    1,177
    Diego Martins
    Aug 15, 2006
Loading...

Share This Page