Sorry I didn't really know how to call my question, hope it fits...
I have a function template which gets an argument as template parameter. For that argument I need to have another template parameter which declares the type of the argument but while calling that function later on, I would like to omit the type of the argument. So, I would like to have some kind of typedef (or other mechanism) to get rid of it.
I've seen a similar mechnism with other templates, e.g.
// given: rule is a template with three arguments
template<typename Attr> using Rule = rule<It, Attr(), Skipper>;
When using std::get
one can get along without mentioning the enum class directly:
std::get<static_cast<std::size_t>(Enum::type1)>(tuple);
Here is the function, it is used to access a tuple with an enum (compare: https://stackoverflow.com/a/14835597/2524462)
template<typename Enum, Enum enum, class ... Types>
typename std::tuple_element<static_cast<std::size_t>(enum), std::tuple<Types...> >::type&
get(std::tuple<Types...>& t) {
return std::get<static_cast<std::size_t>(enum)>(t);
}
Since it will be used with several enums, I don't want to hardwire the enum in the template like he did.
It is called like: (1)
std::cout << get<myEnum, myEnum::type1>(tuple);
Questions:
Can I use a typedef or similar to call it just like:
std::cout << new_get < myEnum::type1 > (tuple);
Since it works with std::get, is there a way to have a smarter template, in the first place?
- The get template here has the tuple types as last parameters. Why is it not necessary to spell them out here (1)? How does the compiler figure them out from the given parameter?
I'm using gcc 4.8.1 with C++11 enabled.