Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use binary_search on STL map

Tags:

c++

map

im wondering if you can use the STL binary_search on STL map. I've tried but still cant get it to work

map<int,string> dataMap;

if(binary_search (dataMap.begin().first, dataMap.end().first, key))
    // do some stuff

Thanks in advance! :)

like image 805
mister Avatar asked Dec 13 '22 02:12

mister


1 Answers

STL map is inherently a binary search tree - just use map::find. Using container member functions, where they are present, is preferable to algorithms.

like image 176
Steve Townsend Avatar answered Dec 30 '22 01:12

Steve Townsend