The state of string interpolation

Meta jared771 at gmail.com
Thu Dec 6 20:54:22 UTC 2018


On Thursday, 6 December 2018 at 20:49:08 UTC, Paul Backus wrote:
> On Thursday, 6 December 2018 at 20:45:57 UTC, Meta wrote:
>> On Thursday, 6 December 2018 at 20:00:02 UTC, H. S. Teoh wrote:
>>> Essentially, what you want to be able to do is essentially 
>>> for a template to be able to reference symbols in the 
>>> caller's scope, rather than in the template's scope.
>>
>> Am I missing something? D has this already in the form of 
>> mixin templates.
>
> Mixin templates can *add* symbols to the caller's scope, but 
> they can't refer to *existing* symbols unless they're passed in 
> as template parameters.

mixin template myTpl()
{
     pragma(msg, "name: ", typeof(name));
}

void main()
{
     auto name = "abc";
     mixin myTpl!(); //Prints "name: string"
}

But you do have to know the name of the symbol in advance. I 
assume that's what you mean by "they can't refer to *existing* 
symbols unless they're passed in as template parameters".


More information about the Digitalmars-d mailing list