4-character literal

Rick Mann rmann-d-lang at latencyzero.com
Thu Jan 25 23:46:53 PST 2007


torhu Wrote:

> Try this.
> 
> template MAKE_ID(char[] s)
> {
>      static assert(s.length == 4);
>      const uint ID = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
> }
> 
> enum : uint
> {
>      kSomeConstantValue = MAKE_ID!("abcd")
> }

Of the solutions proposed so far, this is probably the cleanest. Thanks!

Sadly, nothing's really as nice as just saying 'abcd'. What would it take to get multi-character literals added to the language?




More information about the Digitalmars-d mailing list