[container] flat_set using a reversed small_vector

Phil Endecott via Boost-users <[email protected]>
Newsgroups gmane.comp.lib.boost.user
Message-ID <[email protected]>
Dear Experts,

I currently have:

template <typename KEY, typename VALUE, size_t SZ>
using small_flat_map =
  boost::container::flat_map<
    KEY,
    VALUE,
    std::less<KEY>,
    boost::container::small_vector<
      std::pair<KEY,VALUE>,
      SZ
    >
  >;

This works OK, but one thing that I do with it quite often is

  auto i = m.upper_bound(...);
  m.erase(m.begin(),i);

Erasing items at the start of the vector is of course the worst 
thing you can do for performance with a flat_map. So I was wondering 
if I can have a flat_map that stores its elements in the reverse 
order in the underlying vector.

Question: can anyone think of a way to do this that doesn't 
require changing all of the downstream code? For a few 
milliseconds I thought I could just change std::less for 
std::greater but that reverses the externally-visible 
behaviour. Is there some Boost utility that can wrap the 
implementation vector to work in reverse?


Thanks,

Phil.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.