You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code should work without errors but it does not.
Here is the same code in run.dlang.io: https://run.dlang.io/is/7bHmjV
/+ dub.sdl:dependency "dyaml" version="~>0.8.3"+/import dyaml : Loader, Node;
import std : split, to;
classMyClass
{
int x, y, z;
this(Node node)
{
auto parts = node.as!string().split(":");
x = parts[0].to!int;
y = parts[1].to!int;
z = parts[2].to!int;
}
}
voidmain()
{
auto loader = Loader.fromString(`"1:2:3"`);
Node node = loader.load();
auto mc = node.as!MyClass;
}
It fails to compile with the following error message:
onlineapp.d(24,16): Error: template instance `dyaml.node.Node.as!(MyClass)` does not match template declaration `get(T, Flag stringConversion = Yes.stringConversion)()` with `T = onlineapp.MyClass` must satisfy one of the following constraints:` allowed!(Unqual!T) hasNodeConstructor!(Unqual!T)`dmd failed with exit code 1.
It works when inout is added to the constructor.
However, in the most cases, using inout constructor does not work as intended because it creates only const objects unless the constructor is used in inout functions (See https://run.dlang.io/is/9zhOL8).
The text was updated successfully, but these errors were encountered:
However, it seems to be a difficult task because Node.get cannot be pure (it is used in MyClass.this) due to std.variant.Algebraic.type. Using assumePure and @trusted can make Node.getpure but this solution makes more difficult to solve #33.
Using std.sumtype that will be included in 2.097 instead of Algebraic may solve this problem.
The following code should work without errors but it does not.
Here is the same code in run.dlang.io: https://run.dlang.io/is/7bHmjV
It fails to compile with the following error message:
It works when
inout
is added to the constructor.However, in the most cases, using
inout
constructor does not work as intended because it creates onlyconst
objects unless the constructor is used ininout
functions (See https://run.dlang.io/is/9zhOL8).The text was updated successfully, but these errors were encountered: