Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

c++ - Template specialization with variadic templates

template <size_t size, typename ...Params>
void doStuff(Params...) {
}

template <>
void doStuff<size_t(1), int, bool>(int, bool) {

}

int main(int, char**) {
    doStuff<1,int,bool>(1, false);
    return 0;
}

This doesn't compile, the second doStuff declaration gives me error: template-id ‘doStuff<1u, int, bool>’ for ‘void doStuff(int, bool)’ does not match any template declaration but it clearly matches the first declaration with variadic template arguments.

How to specialize variadic templates?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The syntax is correct (afaik, and clang++ accepts it), but your compiler is probably just not up2date yet.

If you use gcc, its variadic template support is quite incomplete, and even very recent svn versions don't support specialization yet (That is just how it is when you use bleeding edge technology, and sadly gcc implemented only a very early incomplete variadic template proposal and since then didn't keep up much, while clang started pretty late, but got pretty complete)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...