On Wednesday, 15 January 2014 05:38:02 UTC+2,
woodb...@gmail.com wrote:
> On Tuesday, January 14, 2014 4:36:46 PM UTC-6, Jorgen Grahn wrote:
> > On Tue, 2014-01-14,
woodb...@gmail.com wrote:
>
> > > Maps may be the worst standard container.
> >
> > Why? I find it invaluable -- it gives you the type->type mapping most
> > modern languages have. (Of course, unordered_map does most of the
> > same things, and for the few cases where it matters, slightly faster.)
> >
>
> I think the pair based interface is flawed and there should
> instead be a container like Boost.intrusive.rbtree in the
> standard.
That tree is not map. Map consists of relations of value
of some type to other value of (possibly some other) type.
Such relations or "mappings" are the point of map. You
can use tree of mappings as map but then you need to
describe what is mapping.
> It wouldn't have to be intrusive, but it
> wouldn't be pair based. Then you're able to work with one
> type rather than two types. No more "first' and "second".
> Multi_index doesn't use pair in its interface either.
Pair is a way to represent a mapping. There may be
endless other ways but notice that you propose none.
If you need a set with specific iteration order or search
criteria then you indeed can use 'boost::intrusive::set' or
'boost::intrusive::multiset'. If you need a set with
several iteration orders or search criteria then you
can use 'boost::multi_index_container'. Those are not
maps. Do not use 'map', 'multimap' or 'unordered_map'
indeed if you just need 'set'.
> I don't know if what Leigh wrote is correct, but if it is
> that would be another strike against maps.
Yes, it is correct about most implementations of vector.
Those reserve automatically double bigger buffer when
vector runs out of space. So benefit is log N and so
the difference diminishes when N grows. If you want
a map implementation based on vector then take
'boost::flat_' (multi)map/set'.
> Maps keep track of the number of elements in them. The
> boost intrusive library gives you the option to not
> have to pay for keeping track of the elements like that.
Saving one integer value is questionable here. It is most
likely that removing it is inefficient like with C string.
C string is less efficient than 'std::string' on most of cases
precisely because of not storing the length anywhere.
So you need to show that you "pay", otherwise it might
be empty claim.
> I think unordered_map is a lame name.
There is 'typedef' if you need better describing alias for type.
Therefore "is a lame name" is not that convincing argument.