Postfix string literal alternative suggestion

Edward Diener eddielee_no_spam_here at tropicsoft.com
Sat Feb 9 15:23:58 PST 2008


Janice Caron wrote:
> On 09/02/2008, Edward Diener <eddielee_no_spam_here at tropicsoft.com> wrote:
>> then one can easily specify the template type using the notation
>> suggested by me to coerce a string literal to the preferred type without
>> having to know the type of the template parameter.
> 
> But you can do that anyway
> 
>     void f(C)()
>     {
>         invariant(C)[] s = "hello world";
>         /*...*/
>     }
> 
> The literal will be coerced, and s will be of the correct type. No
> suffix is needed because this is an assignment statement. You would
> need a suffix in an arbitrary expression, but you don't need one in an
> assignment statement, so all you have to do is break your code up a
> bit more.

Good example. Thanks !

Still I would have preferred not to have to take this roundabout 
approach if possible and coerce the literal directly to the type C.



More information about the Digitalmars-d mailing list