4-character literal

Don Clugston dac at nospam.com.au
Thu Jan 25 23:57:57 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?
> 

In general, I don't think it could work in a useful way. 4-character 
literals do not fit in a uint. It only really works for ASCII.



More information about the Digitalmars-d mailing list