Topic: binary_search


Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/08/13
Raw View
Luddie wrote:

> I find the c++ stl binary_search function is of a very limited use. The
> function returns true or false. Is there a way to get to the address
> (pointer) or the position of the found element?

Perhaps binary_search should have been called test_binary or
present_binary or count_binary (and return an int rather than
a bool).

--

Valentin Bonnard
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Luddie" <NoSpam.@NpSpam.com>
Date: 1999/08/12
Raw View
I find the c++ stl binary_search function is of a very limited use. The
function returns true or false. Is there a way to get to the address
(pointer) or the position of the found element?

TIA
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/08/12
Raw View
In article <7orkcb$8a7$1@mail.pl.unisys.com>, Luddie
<NoSpam.?@NpSpam.com> writes
>I find the c++ stl binary_search function is of a very limited use. The
>function returns true or false. Is there a way to get to the address
>(pointer) or the position of the found element?

So go and look at the three other functions doing binary searches:
lower_bound (returns an iterator to the first matching element)
upper_bound (returns an iterator to the last possible insertion point
for a matching element)
equal_range (effectively returns the pair of iterators for lower_bound,
upper_bound)



Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]