开发者

Is metaprogramming being used in real-world c++ software projects? [duplicate]

开发者 https://www.devze.com 2023-01-13 19:59 出处:网络
This question already has answers here: Closed 12 years开发者_如何学Python ago. Possible Duplicate:
This question already has answers here: Closed 12 years开发者_如何学Python ago.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消