I have a function like this to implement fmap
for C++:
// Given a mapping F from T to U and a container of T, return a container of U
// whose elements are created by the mapping from the original container's
// elements.
template <typename F, template <typename...> typename Container, typename T>
Container<std::invoke_result_t<F&, const T&>> Fmap(F&& f,
const Container<T>& input);
The idea is to use a template template parameter (Container
) to allow accepting any STL-like container. All of the ones in the actual STL I've tried work fine, but a custom container in our codebase doesn't work because it accepts a non-type template parameter
template <typename Key, int Foo = 256>
class MyContainer;
This causes a substitution failure from clang:
template template argument has different template parameters than its corresponding template template parameter
Is there a way to abstract over all template parameters, not just types? If not, is there a better way to structure my code to allow doing what I want without specializing for MyContainer
and all others like it in particular?