generic and template meta class

Discussion in 'C++' started by asit, Mar 8, 2010.

  1. asit

    asit Guest

    What is the diifference between generic programming and template meta
    class programming ?
    asit, Mar 8, 2010
    #1
    1. Advertising

  2. * 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
    Alf P. Steinbach, Mar 8, 2010
    #2
    1. Advertising

  3. asit

    James Kanze Guest

    On Mar 8, 7:48 pm, "Alf P. Steinbach" <> 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
    James Kanze, Mar 11, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nym Pseudo

    META NAME and META HTTP-EQUIV

    Nym Pseudo, Sep 26, 2003, in forum: HTML
    Replies:
    1
    Views:
    548
    =?iso-8859-1?Q?brucie?=
    Sep 26, 2003
  2. christopher diggins
    Replies:
    16
    Views:
    750
    Pete Becker
    May 4, 2005
  3. Replies:
    2
    Views:
    435
  4. A L
    Replies:
    1
    Views:
    510
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  5. Pallav singh
    Replies:
    1
    Views:
    313
    Victor Bazarov
    Jan 6, 2012
Loading...

Share This Page