an std::algorithm approach