3

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.

Community
  • 1
  • 1
user1492900
  • 575
  • 1
  • 8
  • 16
  • Dup'ish: http://stackoverflow.com/questions/3468246/whats-the-use-of-metaprogramming – dirkgently Aug 29 '10 at 15:45
  • 1
    I don't think this is a dupe. That question asks why metaprogramming is ever used, while this question is asking for specific cases where TMP is used. – Billy ONeal Aug 29 '10 at 16:06
  • yes, I want to know examples of real-world projects that are using things like Boost.MPL , but the links are really useful. – user1492900 Aug 31 '10 at 04:55

1 Answers1

3

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
  • 104,103
  • 58
  • 317
  • 552