On Wednesday, 2 January 2019 at 17:49:52 UTC, H. S. Teoh wrote:
On Wed, Jan 02, 2019 at 05:38:41PM +0000, IM via Digitalmars-d-learn wrote:
1- How do I do in D the equivalent of the following C++ macro?

#define OUT_VAL(val) (count << #val << " = " << val << endl)

In particular the #val above to the actual macro argument as a string?
[...]

Try something along these lines:

        import std.stdio;
        void OUT_VAL(alias val)() {
                writefln("%s = %s", __traits(identifier, val), val);
        }
        void main() {
                int i = 123;
                string s = "abc";
                OUT_VAL!i;
                OUT_VAL!s;
        }


T

Thank you so much. Will give this a try.

Reply via email to