1 Reply Latest reply: Feb 20, 2012 2:06 PM by "Oracle, Sandra Whitman-Oracle" RSS

    DBSTL equal_range problem

    915332
      All,

      I'm trying to use a db_multimap with a secondary db, where the key is const char*.

      typedef db_multimap<const char*, patient> idx_patient_t;

      When I use equal_range (or upper_bound) I only get the first key equal to my search, but count returns the right number of equal keys.

      idx_patient_t idx(idx_pat_id_, env_);
      size_t num = idx.count(pat_id.c_str()); //OK, e.g. num = 2
      auto pr = idx.equal_range(pat_id.c_str(), true); //pr.first == pr.second != idx.end()

      However, if I use std::equal_range in this unfriendly form I get the correct result:

      auto pr = equal_range(idx.begin(), idx.end(), make_pair(pat_id.c_str(), ElementRef<patient>(patient())),
      [](pair<const char*, ElementRef<patient>> p1, pair<const char*, ElementRef<patient>> p2)->bool { return strcmp(p1.first, p2.first) < 0;});

      It seems that secondary db's key comparator uses an algorithm similar to strcmp, but db_multimap::equal_range uses a different predicate.
      Is it a bug or a feature, or did I miss something?

      Thanks,
      Tamas

      Edited by: 912329 on Feb 5, 2012 9:34 AM