Changeset 797
- Timestamp:
- 07/07/08 23:30:02 (5 months ago)
- Files:
-
- trunk/phobos/std/typecons.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/typecons.d
r715 r797 25 25 { 26 26 Openmode m = Openmode.READ; 27 string s = toString(m);27 string s = enumToString(m); 28 28 assert(s == "READ"); 29 29 Openmode m1; 30 assert( fromString(s, m1) && m1 == m);30 assert(enumFromString(s, m1) && m1 == m); 31 31 } 32 32 … … 250 250 static if (first) 251 251 { 252 enum string enumParserImpl = "bool enumFromString(string s, ref "~name~" v) {\n" 252 enum string enumParserImpl = "bool enumFromString(string s, ref " 253 ~name~" v) {\n" 253 254 ~enumParserImpl!(name, false, T) 254 255 ~"return false;\n}\n"; … … 316 317 ---- 317 318 enum Abc { A, B = 5, C } 318 string toString(Abc v) { ... }319 Abc fromString(string s) { ... }320 ---- 321 322 The $(D_PARAM toString) function generates the unqualified names of the323 enumerated values, i.e. "A", "B", and "C". The $(D_PARAM fromString) 324 function expects one of "A", "B", and "C", and throws an exception in 325 an y other case.319 string enumToString(Abc v) { ... } 320 Abc enumFromString(string s) { ... } 321 ---- 322 323 The $(D_PARAM enumToString) function generates the unqualified names 324 of the enumerated values, i.e. "A", "B", and "C". The $(D_PARAM 325 enumFromString) function expects one of "A", "B", and "C", and throws 326 an exception in any other case. 326 327 327 328 A base type can be specified for the enumeration like this:
