views:

147

answers:

1

Possible Duplicate:
What's the use of metaprogramming?

I know that in C++, there are libraries providing metaprogramming facitlities, like Boost MPL. But are they really useful in real-world C++ projects ( or just used in rare situations ) ? ( I have the feeling that metaprogramming code are weird and can generate hard-to-debug compilation errors )

Thank you.

+1  A: 

Of course it's useful. Have you ever used std::distance or std::advance? They use metaprogramming to do the right thing for bidirectional/random access iterators. (that is, repeated ++ or -- for bidirectional iterators, and += or -= for random access iterators).

TMP is most useful for libraries that need to do one thing for a type argument, or do another thing for a different type argument (i.e. distance/advance).

Are there insane (e.g. Boost::Spirit::Qi) things you can do with metaprogramming? Sure. That's not the average case though.

Billy ONeal
Thank you for your answer