As mentioned above, you can't do that in C++. However, if you're interested in this kind of metaprogramming, you should definitely take a look at LISP-like [1] languages (I strongly recommend Clojure [2]). What makes these languages so good at metaprogramming is their syntax:
In C++, an expression like
1 + 2
is eventually transformed by the compiler into something like this:
That is, a tree with
+ as the root and
1 and
2 as children
(usually referred to as the syntax tree of the expression).
In LISPs, a big (and difficult) step of this transformation is skipped entirely, as you essentially directly
provide the syntax tree:
(+ 1 2)
(the first term is the root, and the rest of the terms are the children).
This, combined with the fact that data (lists) and code (syntax trees) share the same textual
representation, provide the strong foundation LISP's powerful macro system is built upon.
So, take a look at LISP (or better yet, Clojure) first, and if you like it and want to enjoy this
kind of metaprogramming in C++ too, take a look at
ktg's L++:
https://bitbucket.org/ktg/l
[1]
http://en.wikipedia.org/wiki/Lisp_%28programming_language%29
[2]
http://clojure.org/