Looking to get typeof parseXML return value
jfondren
julian.fondren at gmail.com
Tue Sep 7 04:40:25 UTC 2021
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote:
> Any ideas on how to get the return type of `parseXML` below:
> ```
> import dxml.parser;
>
> const(char)[] _mmfile;
> //_mmfile initialization
>
> TYPE??? _entityRng = parseXML!(simpleXML)(_mmfile);
> ```
> *before* calling parseXML, so that it can be a class member
> variable?
Here's a quick script:
```d
#! /usr/bin/env dub
/++ dub.sdl:
dependency "dxml" version="0.4.0"
+/
import dxml.parser;
import std.stdio : writeln;
struct SomeXML {
EntityRange!(simpleXML, string) xml;
}
struct Again {
typeof(parseXML!simpleXML("")) xml;
}
void main() {
auto xml = parseXML!simpleXML("<x><y></y></x>");
pragma(msg, typeof(xml)); // compile time
writeln(typeid(xml)); // runtime
SomeXML some = SomeXML(xml);
foreach (_; 0 .. 4) {
writeln(some.xml.front);
some.xml.popFront;
}
auto again = Again(xml);
writeln(again.xml.front);
}
```
EntityRange have two template parameters, a Config with four
flags (where simpleXML has all flags set to yes) and the type of
the forward range supplying characters to be parsed. So,
`EntityRange!(simpleXML, string)` works as a type of those are
really what you'll be using, `typeof(parseXML!simpleXML(""))`
works as a type by seeing what type parseXML returns when invoked
like that.
More information about the Digitalmars-d-learn
mailing list