Skip to content

mpv::bmap::find

paulusmas edited this page Jul 30, 2016 · 2 revisions

mpv::bmap::find

iterator find(const key_type& some_value);   (1)
iterator find(const value_type& some_value); (2)

iterator find(const common_type some_value); (3)

If the key and the value of the different type:

1,2) Finds an element with key/value equivalent to key/value

If the key and the value of the same type:

3) If an element is not found by the key, then finds by the value

Example

#include "bmap_head.h"
#include <iostream>

template<class _It>
static void print_if_find(_It search, bool fPrint)
{
  if (fPrint)
    std::cout<<"Found " << *search->first.get() << " " << *search->second.get() << std::endl;
  else
    std::cout << "Not found\n";
}

int main()
{
  mpv::bmap<int,double> bm_dif;  
  bm_dif.insert(10,20.4); 
  bm_dif.insert(5,100.4);
  auto it_dif = bm_dif.find(20.45);
  print_if_find(it_dif, it_dif != bm_dif.end());

  mpv::bmap<int,int> bm_eq;
  bm_eq.insert(150,200);
  auto it_eq = bm_eq.find(200);
  print_if_find(it_eq, it_eq != bm_eq.end());
  return 0;
}
Outputs
Not found
Found 150 200

Clone this wiki locally