Sorting lists by struct member variables

A

Alf P. Steinbach

* Kai-Uwe Bux:
Right, I was not precise. The actual objects in a vector might undergo
copy-destroy cycles. However, the _values_ are not vanishing from the
sequence unless you erase them. I have a tendency to consider the
copy-destruction way of moving around objects that happens when a vector
reallocates an artifact that does not affect identity of objects on a
conceptual level. However, since the standard defines an object to be a
region of memory, formally, the identity of the object changes.

Well, yeah, I wasn't precise either.

The case I was thinking of was creating objects by inserting them in a
list, and using pointers to those objects elsewere.

That is very risky when using a vector, because inserting a new object
may invalidate existing pointers. With a list all you have to remember
is to not destroy any list elements. Until pointer no longer used.

Cheers,

- Alf
 
A

Alf P. Steinbach

* Jerry Coffin:
Work, maybe. Work well, almost certainly not.

Depends on the programmer. Works exceedingly well in general. :) That
means: guaranteed behavior.

But I saw elsethread that you couldn't imagine a use-case.

One is to create objects by inserting them in a list, the list as an
object repository, and keeping pointers to those objects around
elsewhere. Can of course also and in general be better done by using
smart pointers. However, it might be a speed optimization.

Thanks (largely) to the wonders of rvalue references, C++ 0x won't
require assignment or copy construction even for items in a vector. For
those writing merge sorts (for one example) the ability to have a vector
of streams will be kind of nice...

Interesting!

Can you have an array of rvalue references?

Cheers,

- Alf
 
J

Jerry Coffin

* Jerry Coffin:

Depends on the programmer. Works exceedingly well in general. :) That
means: guaranteed behavior.

I'm sorry to be impolite, but it sounds to me like you're just playing
Humpty Dumpty, simply choosing your own defintion for things, deciding
that what I would call working poorly should eally be called working
exceedingly well.
But I saw elsethread that you couldn't imagine a use-case.

One is to create objects by inserting them in a list, the list as an
object repository, and keeping pointers to those objects around
elsewhere. Can of course also and in general be better done by using
smart pointers. However, it might be a speed optimization.

I remain unconvinced.
Interesting!

Can you have an array of rvalue references?

I'm not sure, but I don't think so. This works (in part) by allowing you
to specify how an object will be created in place rather than only
specifying something like an existing object that will be copied into
the vector.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top