samedi 1 octobre 2016

Data Structure subject to Comperator

I have defined class that maintains a sorted map of doubles maps that to other data structures. Depending on the use case I want that other to be in ascending or descending order.

struct Book {
  std::map<double, Level> levels;

  // More complexity ...

  void process(Tick &t);

  const unsigned amount;

  // More stuf ...

  Book(const unsigned amount) :  levels(), id_price() {}

};

Ideally, this should be specified in the constructor for Book. I could for example pass std::less<double>() but that won't work because I can't use variables to declare the map levels, right? Would it work with templates? I don't want to make it type generic. It should be doubles to not add unnecessary complexity. Ideas?

Aucun commentaire:

Enregistrer un commentaire