D: Create an array of template objects

I'm trying to create an array of objects Regex

, for example Regex[] regexes;

. Compilation failed with main.d(46): Error: template std.regex.Regex(Char) is used as a type

.

I find the documentation cryptic. All I understand is that templates generate code when compiled, but I can't see what's stopping me from creating the array Regex

.


There's an existing question on StackOverflow with the same problem, but it deals with C ++, not D.

+3


source to share


1 answer


You cannot create a regex object without first instantiating the pattern with a type. this is because the actual type is generated at compile time based on the type of the instance you are creating. The Regex itself is not an actual type, it is just a template function to generate a type when instantiated.

In this case, you probably want to change:

Regex[] regexes;

      



in

Regex!char[] regexes;

      

to tell the compiler that your regex contains characters as opposed to some derived type. This means that you are creating a Regex template of type char.

+6


source







All Articles