Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Nice, as long as you can convert the characters in place. What if your source string is const? That seems to make it a bit more messy (e.g. it doesn't look like you can use f.tolower() ), since you need to put the characters in a new string. Would you use transform() and something like std::bind1st( std::mem_fun() ) for the operator? Commented Aug 17, 2016 at 6:09
  • For a const string, we can just make a local copy and then convert it in place. Commented Aug 29, 2016 at 14:53
  • Yeah, though, making a copy adds more overhead. Commented Sep 4, 2016 at 20:49
  • You could use std::transform with the version of ctype::tolower that does not take pointers. Use a back inserter iterator adapter and you don't even need to worry about pre-sizing your output string. Commented Apr 24, 2017 at 2:11
  • Great, especially because in libstdc++'s tolower with locale parameter, the implicit call to use_facet appears to be a performance bottleneck. One of my coworkers has achieved a several 100% speed increase by replacing boost::iequals (which has this problem) with a version where use_facet is only called once outside of the loop. Commented May 23, 2017 at 12:23