3 ms·
Can the std::transform version be written without a lambda? std::transform(buf, buf + size, buf, toupper);
by ufo 7y ago
Can the std::transform version be written without a lambda?
std::transform(buf, buf + size, buf, toupper);
- BeeOnRope 7y agoYes, it can! In fact I had that at some point and clobbered it with a git reset (the perils of developing on two machines and once and using git a sync mechanism). Fixed [1] and credited. --- [1] https://github.com/travisdowns/travisdowns.github.io/commit/cff0322d9b45d9ec18a8a069f7429589574b8b83 https://github.com/travisdowns/travisdowns.github.io/commit/...
- account42 7y agoThis could actually change performance though as the lambda version gives you a unique templace instantiation of std::transform while the non-lambda version requires std::transform to be inlined into the caller (or cloned to an argument-specific version) before the compiler can make any optimizations based on its knowledge of toupper.
- BeeOnRope 7y agoGood point. I would usually expect std::transform to be inlined, since it is quite simple - but it may not be and it's a very good point in general regarding the optimization probability for function pointers versus lambdas. Ultimately, I ended up reverting the change, so using a lambda based on the advice the taking the address of a standard-library function is verboten, since they may introduce overloads at any time [1]. --- [1] https://twitter.com/foonathan/status/1197051249822195712 https://twitter.com/foonathan/status/1197051249822195712
- YSFEJ4SWJUVU6 7y agoYes and no. Technically that results in UB with many inputs with platforms that use a signed char type.