Storing States in C++ Metaprogramming?

2019-07-29 15:04发布

问题:

Is it possible to store states in C++ metaprograms? I'm not entirely sure what I mean, but I want a template class that can be "assigned" to, e.g. state::value can be changed via the use of C++ templates.

I know I probably sound very vague, but I hope someone understands what I'm talking about (also please no Boost.MPL).

回答1:

It's not possible, the TMP part of C++ is a purely functional language without the concept of side effects.



回答2:

That would be a heaven for bugs.

It would also violate the template single-instantiation rule, and it will blow up the size of your program (not to mention confusing the heck out of you).