Fixed the number of template arguments from the variation template

template <template <typename> class F> struct call_me {}; template <typename T> struct maybe; template <typename... T> struct more; int main() { call_me<maybe> a; // ok call_me<more> b; // error } 

I understand why call_me<more> fails. But I want this to work.

Is there a workaround that does not require a change to call_me (or add specialization to it)?

+4
source share
3 answers
 template <template <typename> class F> struct call_me {}; template <typename T> struct maybe; template <typename... T> struct more; template <template <class...> class F> struct just_one { template <class A> using tmpl = F<A>; }; int main() { call_me<maybe> a; call_me<just_one<more>::tmpl> b; } 

Not quite equivalent, but perhaps close enough.

+4
source
 template <typename T> using onemore = more<T>; int main() { call_me<onemore> b; } 
+1
source

You can wrap more :

 template <template <typename...> class Tmpl> struct variwrap { template <typename> struct Dummy { template <typename ...Brgs> struct rebind { typedef Tmpl<Brgs...> other; }; }; }; 

Now you can say call_me<variwrap<more>::Dummy> , and the consumer can use F::rebind<Args...>::other to restore more<Args...> . Of course, call_me does not know that F has a rebind member, so you need to add specialization.

Ugh.

0
source

All Articles