dimanche 5 novembre 2017

Map with custom comparator functor

I'm having trouble using a custom comparator with a map.

I have a map of unique_ptr<const char> to int and I have implemented a comparator functor to sort by the internal pointer (a raw string).

using Name = unique_ptr<const char>;

struct NameComparator {
  bool operator()(const Name& a, const Name& b) const {
    cout << "DEBUG" << endl;
    return strcmp(a.get(), b.get()) < 0;
  }
};

map<Name, int, NameComparator> data;

I've put a "debug" print in the comparator. When I do data.find(Name("stuff")) nothing is displayed. Am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire