This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Extending Temporary buffer for rvalues

I wanted to post this patch separate from my other work, as it might be controversial (but hopefully isn't).

This patch changes _Temporary_buffer so that rather than using uninitalised_fill_n, it 'moves' the first value from the range being sorted along the uninitalised range, then back to where it started.

This isn't slow -- we already special case PODs so there isn't really any opportunity for the compiler to change the code into a memset or something similar.

I believe also the code is fine from the point of view of correctness. One problem is that if one of these constructors throws, the '*first' value is lost. However, if any constructor throws once the main body of the algorithm has begun, values could still be lost before, even in C++03, so I do not believe this harms the algorithm.

If this patch is acceptable, then the rest of the C++0x changes to sort are, I believe, non-contraversal.

If this patch is OK, you are welcome to apply this patch as is, or wait for a large patch which subsumes it.

Thanks, Chris

Attachment: temporary_buffer_rvalue.patch
Description: Binary data

2009-08-26 Chris Jefferson <>

* include/bits/stl_tempbuf.h (_Temporary_buffer::_Temporary_buffer) :
Extend to work with move-only types.
* testsuite/25_algorithm/stable_sort/ : New
* testsuite/util/testsuite_hooks.h : Add operator< to copy_tracker.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]