Topic: list<T>: :push_back_ptr()?


Author: willer@carolian.com (Steve Willer)
Date: 1996/06/05
Raw View
Lately, I've been contemplating the usage of the STL for containing
objects that have non-trivial copy operations (basically because that's
what I'm using right now with my own code). The conclusion I came to was
that the best way to avoid copy operations would be to use a list
instead of a vector or deque (which I believe is correct).

However, this leaves the push_back() or insert() operation with a copy
operation that in many cases is unnecessary. I was wondering if the
standards committee has ever considered the possibility of a specialized
version of push_back() and insert() that accepts a *pointer* to an
object? These functions would grab ownership of the pointed-to object
without ever copying it.

Yes, it seems a bit like a hack, but it has the same sort of compromise
feel as, say, list::sort() vs. ::sort().
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Nathan Myers <ncm@cantrip.org>
Date: 1996/06/05
Raw View
Steve Willer wrote:
>
> Lately, I've been contemplating the usage of the STL for containing
> objects that have non-trivial copy operations (basically because that's
> what I'm using right now with my own code). The conclusion I came to was
> that the best way to avoid copy operations would be to use a list
> instead of a vector or deque (which I believe is correct).
>
> However, this leaves the push_back() or insert() operation with a copy
> operation that in many cases is unnecessary. I was wondering if the
> standards committee has ever considered the possibility of a specialized
> version of push_back() and insert() that accepts a *pointer* to an
> object? These functions would grab ownership of the pointed-to object
> without ever copying it.

Surely you realize that list<> doesn't operate on pointers to the
contained objects, but rather pointers to list nodes.

If you are moving objects from one list to another, you can
use member splice() to avoid copying in that case.

Nathan Myers
ncm@cantrip.org
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]