Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > generic and template meta class

Reply
Thread Tools

generic and template meta class

 
 
asit
Guest
Posts: n/a
 
      03-08-2010
What is the diifference between generic programming and template meta
class programming ?
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-08-2010
* 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
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      03-11-2010
On Mar 8, 7:48 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * 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,


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.

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error :: specialization of Template Function on Meta - Template Class Pallav singh C++ 1 01-06-2012 06:44 PM
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
Generic class in a non generic class nramnath@gmail.com Java 2 07-04-2006 07:24 AM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
META NAME and META HTTP-EQUIV Nym Pseudo HTML 1 09-26-2003 09:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57