Reputation: 2018
#include <tuple>
#include <iomanip>
template <typename T, typename ...L>
struct foo{};
template <typename T>
struct bar{
using toto = T;
};
template <template<typename T, typename ...L> class F>
struct bar<F>{
using toto = T
};
int main(){
bar<foo<int,char,char>> a;
}
I want to specialize bar
when the argument is a class that has at least one template argument <typename T, typename ...L>
I tried :
template <template<typename T, typename ...L> class F>
struct bar<F<T,L...>>{
using toto = T
};
and
template <template<typename , typename ...> class F, typename T, typename ...L>
struct bar<F<T,L...>>{
using toto = T
};
which may have made sense, but I couldn't get it right
Upvotes: 1
Views: 57
Reputation: 302698
There's a few syntatic issues here.
bar
is a template that takes one type argument. So any partial or explicit specialization of bar
must also take one type argument.
template <template<typename T, typename ...L> class F>
struct bar<F> {
Here, the T
and L
names are irrelevent, and really you're specializating on a template template. That doesn't match. You'd have to specialize on a specific instantiation of F
:
template <template<typename , typename ...> class F,
typename T, typename... L>
struct bar<F<T, L...>> {
You're missing a semicolon:
using toto = T;
^^
Your declaration of main
is missing parentheses:
int main() {
bar<foo<int,char,char>> a;
}
Upvotes: 0
Reputation: 43662
You forgot a lot of stuff on your sample, syntactically speaking
template <typename T, typename... L>
struct foo{};
template <typename T>
struct bar {
using toto = T; // Semicolon missing
};
template <template<typename, typename...> class F, typename T, typename... L>
struct bar<F<T,L...>> { // Wrong pack expansion
using toto = T;
};
int main() { // () missing
bar< foo<int,char,char> > a; // Pass the parameters to foo since you're
// partially specializing bar to just do that
}
Upvotes: 1
Reputation: 65590
Your ideone code just has a bunch of typographical errors:
struct bar<F<T,...L>>{
//should be
struct bar<F<T,L...>>{
//missing brackets
int main{
//missing semicolon
using toto = T
bar<foo, int,char,char> a;
//should be
bar<foo<int,char,char>> a;
Upvotes: 1