First problem: it doesn't understand enums, it seems to be a bug:
```
enum TopicMask : string
{
divider = "/",
oneLevelMask = "+",
multiLevelMask = "#",
system = "$",
level = "[^"~divider~oneLevelMask~multiLevelMask~"]*",
publishMask = "^("~divider~"|"~level~")+$"
}
bool topicIsValid(string topic) pure
{
import std.regex;
auto mask = ctRegex!(TopicMask.publishMask);
return !topic.matchFirst(mask).empty;
}
```
result:
/usr/include/dmd/phobos/std/regex/package.d(376,20): Error:
template std.array.Appender!(TopicMask).Appender.put cannot
deduce function from argument types !()(TopicMask), candidates
are:
/usr/include/dmd/phobos/std/array.d(2983,10):
std.array.Appender!(TopicMask).Appender.put(U)(U item) if
(canPutItem!U)
/usr/include/dmd/phobos/std/array.d(3011,10):
std.array.Appender!(TopicMask).Appender.put(Range)(Range items)
if (canPutConstRange!Range)
/usr/include/dmd/phobos/std/array.d(3020,10):
std.array.Appender!(TopicMask).Appender.put(Range)(Range items)
if (canPutRange!Range)
/usr/include/dmd/phobos/std/regex/package.d(387,15): Error:
cannot implicitly convert expression `app.data()` of type
`string` to `TopicMask`
/usr/include/dmd/phobos/std/regex/package.d(422,19): Error:
template instance std.regex.internal.parser.Parser!(TopicMask,
CodeGen) does not match template declaration Parser(R, Generator)
if (isForwardRange!R && is(ElementType!R : dchar))
/usr/include/dmd/phobos/std/regex/package.d(393,25): Error:
template instance std.regex.regexImpl!(TopicMask) error
instantiating
/usr/include/dmd/phobos/std/regex/package.d(401,17):
instantiated from here: regex!(TopicMask)
/usr/include/dmd/phobos/std/regex/package.d(431,19):
instantiated from here: regex!(TopicMask)
/usr/include/dmd/phobos/std/regex/package.d(453,54):
instantiated from here: ctRegexImpl!("^(/|[^/+#]*)+$", [])
source/mqttd/topic.d(48,14): instantiated from here:
ctRegex!("^(/|[^/+#]*)+$", [])
If I change ctRegex!(TopicMask.publishMask) to
ctRegex!("^(/|[^/+#]*)+$") I run into next error:
source/mqttd/topic.d(48,26): Error: pure function
'mqttd.topic.topicIsValid' cannot call impure function
'std.regex.matchFirst!(string, StaticRegex!char).matchFirst'
source/mqttd/topic.d(48,26): Error: pure function
'mqttd.topic.topicIsValid' cannot call impure destructor
'std.regex.Captures!(string, ulong).Captures.~this'
Is there any change to use regex inside or pure function? I just
need some pure bool test() method to test string against the mask.