Template string literal?

Simen kjaeraas simen.kjaras at gmail.com
Wed Mar 16 14:41:04 PDT 2011


On Wed, 16 Mar 2011 22:39:00 +0100, Denis Koroskin <2korden at gmail.com>  
wrote:

> On Thu, 17 Mar 2011 00:30:17 +0300, Jacob Carlborg <doob at me.com> wrote:
>
>> Is it possible to declare string literal of a template type, something  
>> like this:
>>
>> void bar (const(T)[] a) {}
>>
>> void foo (T) (const(T)[] a)
>> {
>>      bar("abc"T);
>> }
>>
>> foo("def"w);
>>
>> In this case the string literal passed to "bar" would be of the type  
>> "wstring".
>>
>> Is this somehow possible or do I have to create a variable?
>>
>
>
>> void bar (const(T)[] a) {}
>>
>> void foo (T) (const(T)[] a)
>> {
>        bar!(T)("abc"); // same as: const(T)[] abc = "abc"; bar(abc);
>> }
>>
>> foo("def"w);

I shoulda thought of that. Much cleaner than my solution.

-- 
Simen


More information about the Digitalmars-d-learn mailing list