digitalmars.D.learn - Tyepof regex
- Tiberiu Gal (15/15) Jan 13 2014 what is the type returned by regex function?
- Brad Anderson (14/29) Jan 13 2014 The type is a template called Regex that is templated on the
- Tiberiu Gal (2/38) Jan 13 2014 thank you
- Nicolas Sicard (5/7) Jan 13 2014 Or: typeof(regex(""))
- Tiberiu Gal (5/20) Jan 13 2014 It's Regex!char
what is the type returned by regex function? I want to store a regex member because I need to reuse it multiple times. Can this be done? class A { protected SomeTypeName regexPattern; void load() { string str; // obtain a regex pattern and store it as str. regexPattern = regex( str ); } bool matches() { // use regexPattern } }
Jan 13 2014
On Monday, 13 January 2014 at 20:53:55 UTC, Tiberiu Gal wrote:what is the type returned by regex function? I want to store a regex member because I need to reuse it multiple times. Can this be done? class A { protected SomeTypeName regexPattern; void load() { string str; // obtain a regex pattern and store it as str. regexPattern = regex( str ); } bool matches() { // use regexPattern } }The type is a template called Regex that is templated on the character width. struct A { Regex!char re; this(string str) { re = regex(str); } } There is also std.traits.ReturnType you can use for more complex types or voldemort types.
Jan 13 2014
On Monday, 13 January 2014 at 20:59:28 UTC, Brad Anderson wrote:On Monday, 13 January 2014 at 20:53:55 UTC, Tiberiu Gal wrote:thank youwhat is the type returned by regex function? I want to store a regex member because I need to reuse it multiple times. Can this be done? class A { protected SomeTypeName regexPattern; void load() { string str; // obtain a regex pattern and store it as str. regexPattern = regex( str ); } bool matches() { // use regexPattern } }The type is a template called Regex that is templated on the character width. struct A { Regex!char re; this(string str) { re = regex(str); } } There is also std.traits.ReturnType you can use for more complex types or voldemort types.
Jan 13 2014
On Monday, 13 January 2014 at 20:59:28 UTC, Brad Anderson wrote:There is also std.traits.ReturnType you can use for more complex types or voldemort types.Or: typeof(regex("")) BTW, how does ReturnType handle overloads? -- Nicolas
Jan 13 2014
On Monday, 13 January 2014 at 20:53:55 UTC, Tiberiu Gal wrote:what is the type returned by regex function? I want to store a regex member because I need to reuse it multiple times. Can this be done? class A { protected SomeTypeName regexPattern; void load() { string str; // obtain a regex pattern and store it as str. regexPattern = regex( str ); } bool matches() { // use regexPattern } }It's Regex!char class A { protected Regex!char regexPattern; ...
Jan 13 2014