digitalmars.D.learn - assert format of a string before a mixin
- ddcovery (6/18) Sep 27 2020 I have a "variation" of "unaryFun" that I name "unaryProp" that,
- Adam D. Ruppe (6/10) Sep 27 2020 Not really and I'd actually suggest not trying because even if it
- ddcovery (2/13) Sep 27 2020 Thanks Adam.
I have a "variation" of "unaryFun" that I name "unaryProp" that, basically, doesn't require to specify "a." at the beginning of the expression.template unaryProp(alias propName) { static assert(is(typeof(propName) : string), "Sorry, propName must be an string"); auto unaryProp(ElementType)(auto ref ElementType a) { return mixin("a." ~ propName); } } assert( "hello".unaryProp!"length" == 5 );Problem is I need to check that "propName" is a valid property name at compile timei.e. checking this Regex expression `^[a-zA-Z_]*[a-zA-Z0-9_]*[a-zA-Z][a-zA-Z0-9_]*$`Is there any way to check a regular expression at compile time?
Sep 27 2020
On Sunday, 27 September 2020 at 21:38:43 UTC, ddcovery wrote:Not really and I'd actually suggest not trying because even if it did work, it'd probably be very slow. But that regex there is pretty easy to translate to a little hand-written loop function that would do the job runtime, ctfe both and do it quickly.i.e. checking this Regex expression `^[a-zA-Z_]*[a-zA-Z0-9_]*[a-zA-Z][a-zA-Z0-9_]*$`Is there any way to check a regular expression at compile time?
Sep 27 2020
On Sunday, 27 September 2020 at 21:41:25 UTC, Adam D. Ruppe wrote:On Sunday, 27 September 2020 at 21:38:43 UTC, ddcovery wrote:Thanks Adam.Not really and I'd actually suggest not trying because even if it did work, it'd probably be very slow. But that regex there is pretty easy to translate to a little hand-written loop function that would do the job runtime, ctfe both and do it quickly.i.e. checking this Regex expression `^[a-zA-Z_]*[a-zA-Z0-9_]*[a-zA-Z][a-zA-Z0-9_]*$`Is there any way to check a regular expression at compile time?
Sep 27 2020