Thread: Template metaprogramming, whats the point?

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    The best use for template metaprogramming is when you have some value in your program, you know will be static, and you know can be completed in some time (not an infinite loop).
    False.

    So the main use is in a situation where, perhaps you need to know constant value but all you have is the formula and the data to get the value.
    False.

    Paraphrasing my own earlier comments: meta-programming is about generation.

    That isn't the best use; that is the only use.

    You can use meta-programming to:

    generate a value by applying some algorithms to other values.

    generate multiple values by applying some algorithms to other values.

    generate an operation by sequencing other operations.

    generate an operation by nesting other operations.

    generate multiple operations by expanding a meta-program with several target operations.

    generate an algorithm by sequencing operations or other algorithms.

    generate an algorithm by nesting operations or other algorithms.

    generate multiple algorithms by expanding a meta-program with several target algorithms.

    generate the meta-programs that generate all of these things.

    ...

    generate the meta-programs that generate the meta-programs that generate the meta-programs that...

    You get the point?

    You aren't wrong to say that it can generate a value. You can generate the value. You can also generate the formula that generates the value. You can generate the type that stores the value. You can generate the types that the formula operates on during expansion. You can choose between formulas. You can decide if any formula should be expanded.

    Soma

  2. #17
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838

    generate an operation by sequencing other operations.

    generate an operation by nesting other operations.

    generate multiple operations by expanding a meta-program with several target operations.
    this is relevant to my interests. can you provide an example?

  3. #18
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    can you provide an example?
    O_o

    You know, I don't do a lot of "work for hire". My confidence, eclectic approach, and refusal to use any standard other than my own good judgment gives me an apparent arrogance that isn't really attractive. When I am contracted I'm often asked to solve template implementation issues that only exist because no one bothered to specify how the expansion should behave in the first place. I usually find myself asking "How would you like it to behave?".

    The moral of the story: you need to be more specific.

    -_-

    Not that I could do the area justice with a few simple examples. If you really want to learn, you'll have to do the work.

    If for whatever reason you don't already own "C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond" you should buy it immediately. If you already own it, read chapter three for a good approach to representing arbitrary operations, nested operations, sequential operations, the values that these operators operate on, and the types that represent those values with abstract types as generated by meta-programs. (It also provides an introduction to expression templates.) Until you do own it, you my read the relevant portion "http://www.boost.org/doc/libs/1_37_0/libs/mpl/doc/tutorial/tutorial-metafunctions.html".

    After you feel familiar with the ideas you can grab 'Blitz++' to see how the ideas have been used as a building block for expressive mathematics that generate incredible efficient source. (You don't look at the source. You look at the interface and the output, but you figure out how they did it for yourself.)

    When you've understood that take a look at 'Boost::Spirit' for an extraordinary application of the same idea as applied to entity processing and generation.

    When you've understood that take a look at 'Boost::Spirit::Phoenix'. I've seen people describe it as the ultimate application of the same very simple ideas. It isn't. It is extremely good. I think penultimate would be fair.

    Soma

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And when you've done that, look at Boost.Proto, which is the next evolutionary step of expression template programming.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    ok after some thought on it, i think i get it.

    one example might be if you had a matrix template class of arbitrary dimensions, an operation on a higher order matrix would/could recurse through the operators of the lower orders down to simple row/column operations.
    Last edited by m37h0d; 02-01-2009 at 10:50 AM.

  6. #21
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    And when you've done that, look at Boost.Proto, which is the next evolutionary step of expression template programming.
    Or at the very least a step in the right direction.

    Soma

  7. #22
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    >>When you've understood that take a look at 'Boost::Spirit::Phoenix'. I've seen people describe
    >>it as the ultimate application of the same very simple ideas. It isn't. It is extremely good. I think
    >>penultimate would be fair.

    Unless Boost.Proto or something else succeeded Phoenix, maybe just superior.

    Quote Originally Posted by The Concise Oxford English Dictionary
    penultimate adj. last but one.
    origin C17: from Latin paenultimus, from paene 'almost' + ultimus 'last', on the pattern of ultimate.
    Coming from a recent edition. The entomology makes it seem like it would fit but that is history only I think. In terms of style (and depending on what you were writing about) it might describe one of the last great things a person did, but clearly not the final one.

    I'm being a dick, true, but it's just an excuse to define one of my favorite words.

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by whiteflags View Post
    >>When you've understood that take a look at 'Boost::Spirit::Phoenix'. I've seen people describe
    >>it as the ultimate application of the same very simple ideas. It isn't. It is extremely good. I think
    >>penultimate would be fair.

    Unless Boost.Proto or something else succeeded Phoenix, maybe just superior.



    Coming from a recent edition. The entomology makes it seem like it would fit but that is history only I think. In terms of style (and depending on what you were writing about) it might describe one of the last great things a person did, but clearly not the final one.

    I'm being a dick, true, but it's just an excuse to define one of my favorite words.
    So if soma thinks there's one more step that can be taken with (the ideas behind) phoenix, then wouldn't he be right? (Not that I would presume to put words in his mouth.)

  9. #24
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    *shrug* In my opinion, there is a better word for that. Given the literal definition the "ultimate step" should have been achieved already for the description to be definite.

  10. #25
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    penultimate means second to last...what is the hubbub about now? :-?

  11. #26
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Well if Soma knows what the ultimate application of template metaprogramming is, we will all learn something new.

  12. #27
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    The entomology makes it seem like it would fit but that is history only I think.
    O_o

    You confuse 'entomology' for 'etymology', begin a sentence with "In my opinion", and yet harp on my style?

    Cute.

    Well if Soma knows what the ultimate application of template metaprogramming is, we will all learn something new.
    As I've taken pains to explain, meta-programming has only one purpose: generation.

    The statement regarded the ideas so gloriously presented by 'Boost::Spirit::Phoenix'.

    Also, nowhere did I restrict the statement to meta-programming as it pertains to C++ templates. The concepts are extremely valuable in many languages.

    As for the choice of "penultimate", I simply find it the most appropriate word to describe the implementation. 'Boost::Spirit::Phoenix' has a few problems. If it didn't have those problems, I would have simply said ultimate.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. help with template class using a template node
    By aciarlillo in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2005, 05:46 PM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM