Suppose foo is a template that takes a container type, which itself has one template argument to specify the type of its values:
template <template<typename val_t> class container_t>
struct foo;
For convenience, foo shall take std::vector as a default container. Trouble is that formally std::vector formally has two arguments of which the second has a default. This means ... container = std::vector does not work.
A solution with C++11 would be to define a template alias:
template<typename val_t> using vec_dummy = std::vector<val_t>;
template <template<typename val_t> class container_t = vec_dummy>
struct foo;
I don't like, for readability (you have to search vec_dummy) and also for aesthetic reasons (there's no reason to name that type).
Is there a way to somehow define the template alias anonymously? Other approaches to the problem are of course also warmly welcome.
PS: In reality, foo uses an internal data type as value type for the provided container, so
template <typename container_t = std::vector<int>> struct foo;
is not an option.
Aucun commentaire:
Enregistrer un commentaire