Re: Troubles creating templated inout objects
On Wednesday, 11 July 2018 at 12:55:35 UTC, Timoses wrote: On Tuesday, 10 July 2018 at 18:01:59 UTC, Steven Schveighoffer wrote: You are overthinking :) inout typically is much easier than you expect, until you need to create temporary structs or types with inout members, then it becomes problematic. https://run.dlang.io/is/kosYuC I had to put in a static if, because your function doesn't work once you get down to the array type. See the // fixme comment. Ok, well that helped a tiny bit for the example. I'm trying to reproduce the errors from my project. It's starting to get out of control : D. inout is on a rampage! https://run.dlang.io/is/5TN7XX I guess it's the same as for immutable initialization of arrays. I can't seem to find a proper response to this one.. [...] class TestA(T : T[]) { Test!T[] arr; // ERROR: Can't initialize inout variable in a for loop... this(inout(T[]) arr) inout { // 1: Nope foreach (mem; arr) this.arr ~= test(mem); // 2: Nope //Test!T[] a; //foreach (mem; arr) // a ~= test(mem); import std.algorithm : map; // 3: Nope // this.arr = arr.map!((e) => test(e)).array; } } [...] I guess the problem here is focused around the problem that the incoming type in the constructor is inout and that the constructed object itself is inout. I can't seem to find another way, I'm just blatantly casting now... class TestA(T : T[]) { Test!T[] arr; this(inout(T[]) arr) inout { import std.algorithm : map; import std.range: array; // should be okay to cast to const, won't change anything auto ts = cast(const T[])arr; // should be okay as well, as `test(t)` creates a new object this.arr = cast(inout(Test!T[]))(ts.map!(t => test(t)).array); } } I also found `assumeUnique` in std.exception, or std.experimental.allocator.makeArray. I'm not to sure how they might be able to circumvent the casting though, since I need an inout array of the objects... Am I missing something or is `inout` simply not that well "implemented" yet?
Re: Troubles creating templated inout objects
On Tuesday, 10 July 2018 at 14:34:55 UTC, Timoses wrote: `Unqual` in this case just turns `inout(int[])` into `inout(int)[]`, which is why it complains. That's a side effect of this example [...] See also: https://issues.dlang.org/show_bug.cgi?id=3567
Re: Troubles creating templated inout objects
On 7/11/18 8:55 AM, Timoses wrote: On Tuesday, 10 July 2018 at 18:01:59 UTC, Steven Schveighoffer wrote: You are overthinking :) inout typically is much easier than you expect, until you need to create temporary structs or types with inout members, then it becomes problematic. https://run.dlang.io/is/kosYuC I had to put in a static if, because your function doesn't work once you get down to the array type. See the // fixme comment. Ok, well that helped a tiny bit for the example. I'm trying to reproduce the errors from my project. It's starting to get out of control : D. inout is on a rampage! https://run.dlang.io/is/5TN7XX I guess it's the same as for immutable initialization of arrays. I can't seem to find a proper response to this one.. import std.traits; struct S { int[3] arr; } struct SS { S s; } interface I { inout(I) opIndex(size_t idx) inout; } class Test(T) : I { T member; this(inout T mem) inout { this.member = mem; } inout(Test!T) get() inout { return new inout Test!(Unqual!(typeof(member)))(member); } inout(I) opIndex(size_t idx) inout { static if (is(T == struct)) { switch (idx) static foreach (index, t; T.tupleof) { case index: return new inout Test!(Unqual!(typeof(this.member.tupleof[index]))) (this.member.tupleof[index]); default: return null; } } else return null; } } auto test(T)(inout T t) { return new inout Test!(Unqual!T)(t); } class TestA(T : T[]) { Test!T[] arr; // ERROR: Can't initialize inout variable in a for loop... this(inout(T[]) arr) inout { // 1: Nope foreach (mem; arr) this.arr ~= test(mem); // 2: Nope //Test!T[] a; //foreach (mem; arr) // a ~= test(mem); On the right track, but inside inout (or const or immutable) constructors, the members can only be initialized once. So you have to initialize a local, and then set the member once. The issue is, your input is *also* inout (a necessary condition), so you didn't declare a properly: inout(Test!T)[] a; foreach (mem; arr) a ~= test(mem); this.arr = a; -Steve
Re: Troubles creating templated inout objects
On 7/12/18 4:58 AM, Timoses wrote: On Tuesday, 10 July 2018 at 14:34:55 UTC, Timoses wrote: `Unqual` in this case just turns `inout(int[])` into `inout(int)[]`, which is why it complains. That's a side effect of this example [...] See also: https://issues.dlang.org/show_bug.cgi?id=3567 Responded there, but really this is a misunderstanding of Unqual. Unqual should shallowly strip as much off as it can, but shouldn't allow you to break const. The problem is that for things other than pointers or arrays, it can't provide a tail-const version, so it goes too far. Fixing this will probably break a lot of code, which means we need to find another way. -Steve
Re: Troubles creating templated inout objects
On Thursday, 12 July 2018 at 12:22:34 UTC, Steven Schveighoffer wrote: On 7/11/18 8:55 AM, Timoses wrote: class TestA(T : T[]) { Test!T[] arr; // ERROR: Can't initialize inout variable in a for loop... this(inout(T[]) arr) inout { // 1: Nope foreach (mem; arr) this.arr ~= test(mem); // 2: Nope //Test!T[] a; //foreach (mem; arr) // a ~= test(mem); On the right track, but inside inout (or const or immutable) constructors, the members can only be initialized once. So you have to initialize a local, and then set the member once. The issue is, your input is *also* inout (a necessary condition), so you didn't declare a properly: inout(Test!T)[] a; foreach (mem; arr) a ~= test(mem); this.arr = a; -Steve Aw, thanks! This is much nicer than casting...
Re: Is it feasible to slowly rewrite a C++ codebase in D?
On Wednesday, 11 July 2018 at 20:38:13 UTC, Dukc wrote: On Wednesday, 11 July 2018 at 19:41:37 UTC, Jordi Gutiérrez Hermoso wrote: Just getting it into -betterC territory seems like a very daunting task. You do not need -betterC anymore. At least the LDC frontend will only add linking hooks for what you use, -betterC or no. No need build a stub runtime anymore or give a switch to the compiler to not use the default one. I know because I compile to JavaScript: first to LLVM bitcode, then manual link (with llvm-link), then to JavaScript using Emscripten. I only have to compile those parts of DRuntime and Phobos I use. Its unlikely I could even have a stub runtime to work, so this is the only reason I can use D in my web page to any real degree. Also since 2.079 the GC (and many parts of Phobos) get lazily initialized, so while I think there are still some features that might require initialization, it might also be feasible to simply use normal D. Have you already tried this?
Orange not working?
I am trying to make use of the Orange package, I added the latest version from dub to my project: "orange": "~>1.0.0" and copy pasted the "simple usage" code from https://github.com/jacob-carlborg/orange , but I am getting a long list of errors: ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(714,21): Error: undefined identifier typedef ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(714,21): Error: undefined identifier typedef ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(925,42): Error: template instance `orange.serialization.Serializer.Serializer.serializeInternal!int` error instantiating ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1543,37): instantiated from here: serializePointer!(int*) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(799,56): instantiated from here: objectStructSerializeHelper!(Foo) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(718,28): instantiated from here: serializeObject!(Foo) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(665,26): instantiated from here: serializeInternal!(Foo) source\app.d(19,22):instantiated from here: serialize!(Foo) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\util\Traits.d(135,27): Error: undefined identifier typedef ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1121,20): Error: template instance `orange.util.Traits.isTypedef!(Foo)` error instantiating ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1114,44): instantiated from here: deserializeInternal!(Foo, string) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(995,45): instantiated from here: deserializeInternal!(Foo, string) source\app.d(22,39):instantiated from here: deserialize!(Foo) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\util\Traits.d(135,27): Error: undefined identifier typedef ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1121,20): Error: template instance `orange.util.Traits.isTypedef!int` error instantiating ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1616,63): instantiated from here: deserializeInternal!(int, string) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1220,58): instantiated from here: objectStructDeserializeHelper!(Foo) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1125,41): instantiated from here: deserializeObject!(Foo, string) ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(1114,44): ... (1 instantiations, -v to show) ... ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(995,45): instantiated from here: deserializeInternal!(Foo, string) source\app.d(22,39):instantiated from here: deserialize!(Foo) C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1. Anyone has the library working? my DMD version is: dmd --version DMD32 D Compiler v2.080.0 Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright
Re: Orange not working?
On Thursday, 12 July 2018 at 20:44:43 UTC, JN wrote: I am trying to make use of the Orange package, I added the latest version from dub to my project: "orange": "~>1.0.0" and copy pasted the "simple usage" code from https://github.com/jacob-carlborg/orange , but I am getting a long list of errors: ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(714,21): Error: undefined identifier typedef [...] Hm, v1.0.0 is from 2016 and meanwhile typedef was deprecated https://dlang.org/deprecate.html#typedef . Perhaps use "orange": "~master" to use the latest code.
Re: Orange not working?
On Friday, 13 July 2018 at 05:29:58 UTC, Timoses wrote: On Thursday, 12 July 2018 at 20:44:43 UTC, JN wrote: I am trying to make use of the Orange package, I added the latest version from dub to my project: "orange": "~>1.0.0" and copy pasted the "simple usage" code from https://github.com/jacob-carlborg/orange , but I am getting a long list of errors: ..\..\AppData\Local\dub\packages\orange-1.0.0\orange\orange\serialization\Serializer.d(714,21): Error: undefined identifier typedef [...] Hm, v1.0.0 is from 2016 and meanwhile typedef was deprecated https://dlang.org/deprecate.html#typedef . Perhaps use "orange": "~master" to use the latest code. Looks better, but still doesn't compile: C:\Users\jacek\Desktop\test_orange>dub run Package orange can be upgraded from ~master to 1.0.0. Use "dub upgrade" to perform those changes. WARNING: A deprecated branch based version specification is used for the dependency orange. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead. Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86. orange ~master: target for configuration "" is up to date. test_orange ~master: building configuration "application"... ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1313,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\archives\Archive.d(1348,9): Warning: statement is not reachable ..\sertest\orange-master\orange\serialization\Serializer.d(1215,9): Warning: statement is not reachable C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.