473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Use of lower_bound

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?
Jul 22 '05 #1
1 2221
In article <2t*************@uni-berlin.de>,
Jim West <eg***********@yahoo.com> 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/wg...fects.html#270

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

-Howard
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Vinokur | last post by:
============================= Windows 2000 MinGW 2.0.0.-2 GNU gcc/g++ version 3.2 ============================= I have some question concerning the lower_bound algorithm. ========= C++ code...
3
by: Jaap | last post by:
Hi all, I'm looking for functionality very similar to std::map::lower_bound: I'd like to find the first element whose key is equal to or smaller than the key I pass. In a map filled like...
3
by: Allerdyce.John | last post by:
On page 181 of Effective STL, it said 'It 's knowning when equal_range is a better way to search than lower_bound, knowing when lower bound is preferable to find..." My question is understand...
3
by: Diego Martins | last post by:
Andrew Koenig wrote:
3
by: could.net | last post by:
I have a class board, like this: struct board { int x1, x2, h; int time1, time2; void calculate_time(); void assign(int x1__,int x2__,int h__); }; And I have n boards stored in an array...
1
by: phdscholar80 | last post by:
I am using the following code: #include <vector> #include <algorithm> class A { }; bool comparator( A * b, const char * a )
0
by: mathieu | last post by:
hi there, I do not understand why the following piece of code is not working for me. I have a set of cstrings, where I am trying to find one 'UT'. If I search from "AE" to "OB or OW" everything...
4
by: qlin88 | last post by:
Hi, In STL multi-map, the lower_bound, upper_bound,equal_range all return an iterator. Now ifone wants to iterate from an upper bound towards a lower bound, what would be the best way to do it?...
4
by: RiderOfGiraffes | last post by:
Hi, I'm trying to compile (someone else's) code on SuSE 11.0. It worked fine on SuSE 10.3, but now it's telling me that lower_bound is not a member of std. I'm assuming something has changed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.