Two questions
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Jan 2 17:49:52 UTC 2019
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
--
The easy way is the wrong way, and the hard way is the stupid way. Pick one.
More information about the Digitalmars-d-learn
mailing list