Created
June 18, 2026 22:24
-
-
Save mistificator/4ca599e33518708cefe514656de31e67 to your computer and use it in GitHub Desktop.
collection_cast.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| #include <utility> | |
| #include <iterator> | |
| template < | |
| template <typename...> class Container, | |
| typename OldType, | |
| typename... Args, | |
| typename Converter | |
| > | |
| auto collection_cast(const Container<OldType, Args...>& source, Converter converter) | |
| { | |
| using NewType = decltype(converter(std::declval<const OldType&>())); | |
| Container<NewType> target; | |
| std::transform( | |
| source.begin(), | |
| source.end(), | |
| std::inserter(target, target.end()), | |
| converter | |
| ); | |
| return target; | |
| } |
mistificator
commented
Jun 18, 2026
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment