On 3/17/2012 10:55 AM, Andrei Alexandrescu wrote:
On 3/17/12 12:14 PM, Entity325 wrote:
Who's with me? Anybody have a short(but COMPLETE!) example of code that
makes use of Templates that you actually understand what's going on there?
You're on to something here. Then, as usual, from idea to realization there are
quite a few steps.
I took a complementary approach in TDPL: there's no chapter on templates at all.
Templates are naturally interwoven with whatever topic is at hand, wherever
they're useful. I hoped people would learn templates without even knowing it.
Sans value parameters:
int foo() {
return 3;
}
With value parameters:
int foo(int i) {
return i;
}
Sans type parameters:
struct S {
int i;
}
With type parameters:
struct S(T) {
T i;
}
i.e. templates are type parameters.