Replace for-loop with std::transform() for deep copy.