Home Dashboard Directory Help

std::merge invalidates source data because it uses move semantics by Travis Vitek


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 680313
Opened: 7/21/2011 4:08:18 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
User(s) can reproduce this bug


The merge algorithm moves data from the source ranges into the destination, invalidating the source data. The C++03 standard isn't really clear about whether or not the input range is invalidated, but this is not consistent with what is expected.

I do not believe this behavior is consistent with previous versions of Visual Studio. None of the other implementations I've tested exhibit this behavior, and it is not consistent with the documented behavior of the function (http://msdn.microsoft.com/en-us/library/9ew9xdb2.aspx) or that of the C++0x draft (which explicitly says the source ranges are copied).
Sign in to post a comment.
Posted by Microsoft on 8/15/2011 at 4:49 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11. Both the normal and predicate versions of std::merge() have been fixed.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator10 [Feedback Moderator] on 7/21/2011 at 6:40 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 7/21/2011 at 4:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Viorel_ on 7/21/2011 at 11:35 PM
Use constant iterators:

    const auto & v0c = v0;
    const auto & v1c = v1;
    merge (v0c.begin(), v0c.end(), v1c.begin(), v1c.end(), tmp.begin());
File Name Submitted By Submitted On File Size  
t.cpp 7/21/2011 992 bytes