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.


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;



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.



All Articles