Fastest way to check using if identifier has already been defined, using static if or similar?

Stefan Koch uplink.coder at googlemail.com
Thu Jun 4 14:40:04 UTC 2020


On Thursday, 4 June 2020 at 14:20:45 UTC, Q. Schroll wrote:
> On Thursday, 4 June 2020 at 09:03:40 UTC, Simen Kjærås wrote:
>> string exists(string s) {
>>     return "__traits(compiles, { mixin(\"alias _ = "~s~";\"); 
>> })";
>> }
>
> Little nitpicking, but D has many forms of string literals. 
> Escaping is hard to read especially without syntax 
> highlighting. Escaping to me is an old hack C did we shouldn't 
> really use.
>
>     string exists(string s) {
>         return `__traits(compiles, { mixin("alias _ = ` ~ s ~ 
> `;"); })`;
>     }
>
> The _ as a name, to me, proves that a __traits(freshName), that 
> returns a string that is distinct from every symbol name 
> visible from the point it's defined,  would be useful in these 
> occasions. Because if someone used _ as an identifier in a 
> context where the `exisits` function is used, it might fail.

Don't have a unique name facility now?
... I remember seeing one.
Could have been a mirage I guess.


More information about the Digitalmars-d-learn mailing list