February 12, 2008 Re: CTFE implementation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote: > Don Clugston schrieb: >> Looks like a CTFE bug. >> Try creating the GUID struct in place, that often works better. >> >> return GUID(HexToInt( str[1 .. 9] ), ... >> [HexToInt( str[25+2*0 .. 25+2*0], ... >> ,HexToInt( str[25+2*5 .. 25+2*5]] ); > > I tried this without luck: opCall definitely won't work with CTFE yet. But struct constructors work in every case I've ever tried. > struct __GUID{ > static __GUID opCall( uint Data1_, ushort Data2_, ushort Data3_, ubyte[8] Data4_ ){ > __GUID s; > s.Data1 = Data1_; > s.Data2 = Data2_; > s.Data3 = Data3_; > s.Data4[0..8] = Data4_[0..8]; > return s; > } > align(1): > uint Data1; > ushort Data2; > ushort Data3; > ubyte[8] Data4; > } > alias __GUID GUID; > > GUID IIDFromString(char[] d) { > return GUID(1,2,3,[0,1,2,3,4,5,6,7]); > } > > > |
February 12, 2008 Re: CTFE implementation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | Frank Benoit wrote: > Don Clugston schrieb: >> Looks like a CTFE bug. >> Try creating the GUID struct in place, that often works better. This works. I reduced the size of Data4 bcos I was lazy -- you'll need to add the other 4 members private static GUID IIDFromString( char[] str ){ assert( str.length is 38 ); assert( str[0] is '{' ); assert( str[9] is '-' ); assert( str[14] is '-' ); assert( str[19] is '-' ); assert( str[24] is '-' ); assert( str[37] is '}' ); return GUID(HexToInt( str[1 .. 9] ), HexToInt( str[10 .. 14] ), HexToInt( str[15 .. 19]), [cast(ubyte)HexToInt( str[20 .. 22] ), HexToInt( str[22 .. 24] ), HexToInt( str[25+2 .. 25+1*2]),HexToInt( str[25+1*2 .. 25+2*2]), // other 4 entries...]); } const GUID IIDJavaBeansBridge = IIDFromString("{8AD9C840-044E-11D1-B3E9-00805F499D93}"); |
Copyright © 1999-2021 by the D Language Foundation