Different methods of implementing variable-length templated classes

C

Chris Jefferson

Now, C++ doesn't actually provide true variable-length templated
classes, for example you can't do (as I found recently!)

template<class T>
class tuple { ... }

template<class T, class U>
class tuple { ... }

There appear to be two main ways of "faking" this.

In "modern C++ design", a system of encoding lists of types as a single
type is used. However I much perfer the "default arguments" methods, like:


template<class T=EmptyClass, class U=EmptyClass>
class tuple;

template<class T>
class tuple<T,EmptyClass>
{ (implement length 1 here) }

....


As it looks much more natural to the user. Is there some reason that
encoding types as a typelist is better?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top