Implementing an optimized alternative to std::transform