but you havent given the typelist example yetOriginally Posted by manutd
but you havent given the typelist example yetOriginally Posted by manutd
You just want a most basic one?
at least an infinite number of types should be possibleOriginally Posted by manutd
Yes, but you need to be more specific. Here's one, holding all floating points:Of course there are other ways to do this, but this is one.Code:template <class H, class T> struct typelist { typedef H head; typedef T tail; }; class null_typelist {}; typedef typelist<float, typelist<double, typelist<long double, null_typelist> > > fpt;
C++ Templates: The Complete Guide was loaned to me by my boss and... well, when the boss gives you a book you read it. =) I'm still only about halfway done with it though, so
I enjoy reading this book. It comes off a bit like a book of trivia however. Somethings in it (like eclectic uses of the typename keyword) I can imagine using, but in the years I've coded, it hasn't come up. Other features (the use of export w/ respect to templates) will pretty obviously never be in itself, useful information.
So, is the book useless? Yes and no. The book is not meant as a functional education of templates. Also, it's not really better than just reading the standard as a reference. The book is mainly of interest because it discusses obscure template features.
These obscure features are part of the language for the sake of addressing fundamental problems with templates. Reading about these makes you consider the nature of the beast. If you were, say, going to write a language which uses templates, then this would be a very good read because it gives you a perspective of the wisdom and flaws of C++'s templates.
Callou collei we'll code the way
Of prime numbers and pings!
lol indeed I should've been more specific. The article you copy pasted that from is a lot longer though with the get functions and all, but even in this small example you're using lots of template features which need explaining.Originally Posted by manutd
a template struct with just 2 typedefs of its template parameters. An empty class as list terminater needs explaining, the recursive template instantiation etc. And the example in the article is just a prerequisite to making VARIANT type unions possible with which you can mix classes and primitive types in a union which is normally not possible.
Also, in modern C++ design he makes way more typelists possible.
And this is just 1 thing you can do with metaprogramming, theres much much more.
Definately can use a few books to have all the information packed in one with a good explanation.
No kidding. I gave one example. I didn't explain, it wasn't a tutorial. And, yes, I copied and pasted, to prove my point that this information is available online.
No in the article the features and why he does that etc arent explained either! If you only use the internet to learn templates, then the article only gets useful if you found the other bits of information about metaprogramming at a random site somewhere else.Originally Posted by manutd
but whatever, this thread bores me ^^
I also found a pdf first with no code examples but explanation..I skipped it because I already know how to do this.