Talk:cpp/algorithm/transform
Is the <functional> header really needed in the Example? — Preceding unsigned comment added by 95.49.59.138 (talk • contribs)
- no, it's a leftover from when the example used std::ptr_fun. --Cubbi (talk) 11:46, 23 January 2016 (PST)
Excuse me, but what was wrong with my edit and why did it have to be "fix"ed like this: http://en.cppreference.com/mwiki/index.php?title=cpp/algorithm/transform&curid=789&diff=83193&oldid=83192 ? AFAIK my edit was correct… I resolved the ambiguity by casting toupper to the right pointer to function type. user:T. Canens? — Preceding unsigned comment added by 95.49.59.138 (talk • contribs)
- Anything passed to the
<cctype>
functions should be first be converted to unsigned char. Otherwise, ifchar
is signed and the value is negative, you get undefined behavior. It's not strictly necessary here, but I'd rather not show questionable practices. T. Canens (talk) 13:44, 23 January 2016 (PST)
[edit] Example conflicts with note
In the "Notes" sections it says that "to apply a function that modifies the elements of a sequence" we should prefer `std::for_each`. However, the example below does just that with
std::transform(s.begin(), s.end(), s.begin(), ...)
Is this use good practice? If so, should we clarify why?