generic and template meta class

A

asit

What is the diifference between generic programming and template meta
class programming ?
 
A

Alf P. Steinbach

* asit:
What is the diifference between generic programming and template meta
class programming ?

Whatever the people using the terms define them to mean.

To me "generic programming" mainly just implies having types as arguments (in
C++ one can additionally have values as template arguments), like

template< typename T >
void foo( T const& v ) { std::cout << v << endl; }

while "template meta programming" or TMP is about programming in the type
domain, like

template< typename Head, typename Tail >
struct Cons {};

template< typename ConsList >
struct FirstOf;

template< typename AHead, typename ATail >
struct FirstOf< Cons< AHead, ATail > >
{
typedef AHead T;
};

and going on other type domain "operations" like TailOf, Reversed, InheritAll
and so on.

A good introduction is Andrei Alexandrescu's "Modern C++ Design".


Cheers & hth.,

- Alf
 
J

James Kanze

Whatever the people using the terms define them to mean.
To me "generic programming" mainly just implies having types
as arguments (in C++ one can additionally have values as
template arguments), like
template< typename T >
void foo( T const& v ) { std::cout << v << endl; }
while "template meta programming" or TMP is about programming
in the type domain,

Not only. Or wouldn't you consider the following TMP?

template<int N>
struct Factorial
{
static int const value = N * Factorial<N-1>::value;
};

template<>
struct Factorial<0>
{
static int const value = 1;
};

Roughly, I'd say that TMP was involved anytime specialization,
partitial specialization or function overload resolution is used
to choose which function to call, how to instantiate another
template, or to break recursion (as above). But I don't think
there's really any rigorous definition.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top