dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: What's Template Metaprogramming?

  1. #1
    Join Date
    Jul 2005
    Posts
    9

    What's Template Metaprogramming?

    "...A template is a pattern for creating classes or functions as instances of the template at compile time, similar to the manner in which a class is a pattern for creating objects as instances of the class at runtime. A template takes one or more parameters, and when you instantiate a class or function template, you must supply arguments for the parameters. The classes and functions can have different behaviors or implementations, depending on the arguments. This style of programming is often called generic programming. Templates can also be used to select code at compile time, affect the behavior of generated code, and set policies. This style of programming is often known as template metaprogramming..."

    In this paragraph i do not understand the sentence " This style of programming is often known as template metaprogramming", what template metaprogramming is, can you give me some code example.
    Good luck to all of you.
    Topcoder 7/24/05.
    Last edited by Danny; 07-24-2005 at 05:24 PM.

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    template meta programming is a very advance topic that is over the head of the average C++ programmer, let alone beginners. There's no point in giving aan example because it won't mean much unless you're a template savvy. Understandong TMP is more than knowing how to write a template. You walso need to master the concepts of policies, traits and oter advanced issues such as partial specializations of a class template. You can find an example of a meta function in this 10 Minute Solution. This solution doesn't explain how to write a met function but how to use a readymade one:

    http://www.devx.com/cplus/10MinuteSolution/21712

    BTW, feel OK about this. So far, TMP is mostly useful for writing libraries. It's not yet an everyday programming tool. It will take time for this paradigm to mature and percolate to mainstream programming. My advice is therefore: learn the basics of templates, say start with a simple function template, then a class template.
    Danny Kalev

  3. #3
    Join Date
    Jul 2005
    Posts
    26
    Well, maybe you'll have a look at this:
    http://osl.iu.edu/~tveldhui/papers/T.../meta-art.html

    Very amusing is the following quote (linked from the article):
    In 1994 I saw a very clever C++ program that Erwin Unruh had written and circulated at a C++ standards committee meeting. The program printed out a list of prime numbers at compile-time as error messages. This inspired me to invent template metaprograms. A useful distinction here is that between programs and metaprograms. A metaprogram is a program that manipulates other programs; for example, compilers, partial evaluators, parser generators and so forth are metaprograms. Erwin Unruh's prime number computing template demonstrated that you could use the C++ template system to write compile-time programs. Inspired by his example, I hit on the idea that you could use C++ templates to do metaprogramming, for example constructing specialized algorithms by weaving together fragments of code at compile-time. My view is that Erwin Unruh invented compile-time template programming, and I built on his work to invent template meta-programming. This was work I did at Rogue Wave Software in May of 1994; there was a technical report published that summer, and an article appeared in C++ Report issue of May 1995.

Similar Threads

  1. Replies: 0
    Last Post: 05-20-2002, 09:39 PM
  2. Replies: 0
    Last Post: 04-19-2002, 06:07 AM
  3. Replies: 0
    Last Post: 04-19-2002, 06:02 AM
  4. MSXML template processor error
    By John Rigsby in forum ASP.NET
    Replies: 1
    Last Post: 10-03-2001, 09:39 AM
  5. working with word template
    By Bill in forum VB Classic
    Replies: 0
    Last Post: 11-06-2000, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center