Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #737

Re: Destructive erase for associative containers

Message-ID <cdeb1d5b-e482-47c1-9216-a5780cdcc7a8@googlegroups.com> (permalink)
Newsgroups comp.std.c++
From Öö Tiib <ootiib@hot.ee>
Subject Re: Destructive erase for associative containers
Organization unknown
References <5d9c5e92-7351-430f-8e1a-4c0f25d7b9c8@googlegroups.com>
Date 2014-10-15 13:27 -0600

Show all headers | View raw


On Friday, 10 October 2014 23:00:03 UTC+3, tra...@gockelhut.com  wrote:
> There are a number of use cases where I want to entirely consume the
> contents of an associative container and re-use the memory of the keys. If
> I have an expensive to copy yet cheap to move key type, there is not a
> supported way of moving my key to a new object, even though I am about to
> erase said key from the container. I would love an operation that allowed
> me to extract and re-use the key when I am moving it to another structure.
> All associative containers could benefit from such an operation. The need
> for this operation isn't terrifically common, but I think it is generic
> enough to warrant a discussion.

The problem is that by design of 'std::map' the "key" is const member
of element (key and value pair) and that is member of (unexposed) "node"
of RB tree. That makes the proposed "move" of "key" confusing. How can
it move from const member of  member?

If you need easily extractable and reusable container elements (for
performance reasons) then you can use standard containers that use
pointers or smart pointers as elements or you can use non-standard
containers that have different design that may better fit with such
goal (for example 'boost::intrusive::set' or
'boost::intrusive::multiset').


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

Destructive erase for associative containers travis@gockelhut.com - 2014-10-10 14:51 -0600
  Re: Destructive erase for associative containers Öö Tiib <ootiib@hot.ee> - 2014-10-15 13:27 -0600

csiph-web