Say I have a templated class Wrapper, is there a way to create a type alias template that automatically deduce a container of Wrapper <T> from a container of T, so that:
alias(Wrapper, vector<int>)would becomevector<Wrapper<int>>alias(Wrapper, map<int, string>)would becomemap<Wrapper<int>, Wrapper<string>>alias(Wrapper, array<int, 10>)would becomearray<Wrapper<int>, 10>
So far the best attempt I've got is:
template<template<typename> typename U, template<typename...> typename Container, typename ...T>
using alias = std::remove_cvref_t<decltype(std::declval<Container<U<T>...>>())>;
However there are two problems:
It must be called with syntax like:This version need to be called like(which is not ideal):alias(vector, Type)andalias(map, Key, Value). I would love to usealias(vector<Type>)andalias(map<Key, Value>)if possible.It is not compatible with
std::arraysince the second template parameter ofarrayissize_tnot a type. I guess I could create a second type alias and call the corresponding one based on the container type, but I would prefer not have to do that.