Two questions

IM 3di at gm.com
Wed Jan 2 23:28:36 UTC 2019


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.


More information about the Digitalmars-d-learn mailing list