4-character literal
Gregor Richards
Richards at codu.org
Fri Jan 26 00:04:19 PST 2007
Rick Mann wrote:
> 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?
>
If there is a benevolent force watching over us, there will never be
four-character literals in D X_X
- Gregor Richards
More information about the Digitalmars-d
mailing list