std::find specialization - by PowerGamer1

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 757385 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 8/7/2012 12:44:19 PM
Access Restriction Public


When using std::find with "char" data type, in many cases for-based implementation of std::find is invoked instead of memchr one. To force compiler to use memchr-based implementation of std::find in such a case (see example program) one must use a total of THREE static_casts! This is completely counter-intuitive and absurd.

In all situations when using "char" data type std::find should use memchr.
Sign in to post a comment.
Posted by Microsoft on 10/9/2012 at 4:58 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in the next update to our C++ Standard Library implementation.

I rewrote find() so it's maximally aggressive about activating the memchr() optimization. Specifically, it's now activated when all of these stars align:

* The given iterators are pointers, or things that the STL knows how to unwrap to pointers (this applies to std::vector, std::string, and std::array iterators).

* The elements are char, signed char, or unsigned char. They can be either modifiable or const.

* The given value is integral (of any signedness and any width).

I also fixed a surprising correctness bug in the old implementation. Given a signed char range containing -1, find() should report that 255 is not found within the range, because static_cast<signed char>(-1) != 255. memchr() happily considers them to be equal. We now perform range checks to adapt memchr()'s behavior to find()'s. This includes the special case where, for example, 0xFFFFFFFFUL is outside the [-128, 127] range of signed char, but is equal to the signed char -1 anyways (thanks to the usual arithmetic conversions).

Note: Connect doesn't notify me about comments. If you have any further questions, please E-mail me.

Stephan T. Lavavej
Senior Developer - Visual C++ Libraries
Posted by Microsoft on 8/7/2012 at 7:04 PM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 8/7/2012 at 12:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(