3

I'm trying to create an array of Regex objects, like so: Regex[] regexes;. The compilation fails 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 on compilation, but I don't see what's preventing me from creating an array of Regex.


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

Community
  • 1
  • 1
midrare
  • 2,371
  • 28
  • 48

1 Answers1

6

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

In this case you probably want to change:

Regex[] regexes;

into:

Regex!char[] regexes;

to tell the compiler that your regex contains chars as opposed to some derived type. This means specifically you are instantiating the Regex template with the type char.

Vality
  • 6,577
  • 3
  • 27
  • 48