What's wrong with this BinaryHeap declaration line? Assertion failure in std.container.array.d
What I HAD TO do to get it to compile: programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(Array!(Results!(O,I))([Results!(O,I)()]), 1); programResultsQ.popFront(); What running it says: AssertionFailure at line 381 of std.container.array.d, which looks like: /** Constructor taking a number of items */ this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) { import std.conv : emplace; auto p = cast(T*) malloc(T.sizeof * values.length); static if (hasIndirections!T) { if (p) GC.addRange(p, T.sizeof * values.length); } foreach (i, e; values) { emplace(p + i, e); assert(p[i] == e); /* THIS IS LINE 381 */ } _data = Data(p[0 .. values.length]); } Any ideas. How can I improve this declaration? Using Phobos sometimes is such a mystery.
Re: What's wrong with this BinaryHeap declaration line? Assertion failure in std.container.array.d
On Wednesday, 23 September 2015 at 05:56:08 UTC, Enjoys Math wrote: What I HAD TO do to get it to compile: programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(Array!(Results!(O,I))([Results!(O,I)()]), 1); programResultsQ.popFront(); What running it says: AssertionFailure at line 381 of std.container.array.d, which looks like: /** Constructor taking a number of items */ this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) { import std.conv : emplace; auto p = cast(T*) malloc(T.sizeof * values.length); static if (hasIndirections!T) { if (p) GC.addRange(p, T.sizeof * values.length); } foreach (i, e; values) { emplace(p + i, e); assert(p[i] == e); /* THIS IS LINE 381 */ } _data = Data(p[0 .. values.length]); } Any ideas. How can I improve this declaration? Using Phobos sometimes is such a mystery. I mean initialization... Here's the corresponding declaration: alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), compareResults); /* module scope */ ProgramResultsQueue!(O,I) programResultsQ; /* class member */ The intialization line occurs in the class's ctor.
Re: Unexpected behavior when casting away immutable
On Wednesday, 23 September 2015 at 03:39:02 UTC, Mike Parker wrote: I have a situation where I would like to demonstrate violating the contract of immutable (as an example of what not to do), but do so without using structs or classes, just basic types and pointers. The following snippet works as I would expect: ``` immutable int i = 10; immutable(int*) pi = &i; int** ppi = cast(int**)π writeln(*ppi); int j = 9; *ppi = &j; writeln(*ppi); ``` Two different addresses are printed, so I've successfully violated the contract of immutable and changed the value of pi, an immutable pointer. However, this does not work as I expect. ``` immutable int x = 10; int* px = cast(int*)&x; *px = 9; writeln(x); ``` It prints 10, where I expected 9. This is on Windows. I'm curious if anyone knows why it happens. violating immutable is undefined behaviour, so the compiler is technically speaking free to assume it never happens. At the very least, neither snippet's result is guaranteed to show a change or not. At the most, literally anything can happen.
Re: How to setup mono-D for shared libraries?
On 23/09/15 8:20 AM, Jacob wrote: How do I setup mono-D for creating shared libraries and including them into other projects? When I drag the .d files to create the library from, which is not my own, I get undefined references. I have the lib files, which are a bunch of separate libs, that I want to include into one big lib. Once that's done I want to include that lib into another project. I'd rather not modify si.ini. Are there any tutorials for getting started with Mono-D? (setup, not coding) Well you could go the route of dub, which configuration files can be loaded directly into it as a project.
Re: Unexpected behavior when casting away immutable
On Wednesday, 23 September 2015 at 03:50:44 UTC, Vladimir Panteleev wrote: On Wednesday, 23 September 2015 at 03:39:02 UTC, Mike Parker wrote: ``` immutable int x = 10; int* px = cast(int*)&x; *px = 9; writeln(x); ``` It prints 10, where I expected 9. This is on Windows. I'm curious if anyone knows why it happens. Essentially, because x is immutable, the compiler optimizes writeln(x) to writeln(10). This seems to happen even without -O. I see. Thanks.
Re: Unexpected behavior when casting away immutable
On Wednesday, 23 September 2015 at 03:39:02 UTC, Mike Parker wrote: ``` immutable int x = 10; int* px = cast(int*)&x; *px = 9; writeln(x); ``` It prints 10, where I expected 9. This is on Windows. I'm curious if anyone knows why it happens. Essentially, because x is immutable, the compiler optimizes writeln(x) to writeln(10). This seems to happen even without -O.
Unexpected behavior when casting away immutable
I have a situation where I would like to demonstrate violating the contract of immutable (as an example of what not to do), but do so without using structs or classes, just basic types and pointers. The following snippet works as I would expect: ``` immutable int i = 10; immutable(int*) pi = &i; int** ppi = cast(int**)π writeln(*ppi); int j = 9; *ppi = &j; writeln(*ppi); ``` Two different addresses are printed, so I've successfully violated the contract of immutable and changed the value of pi, an immutable pointer. However, this does not work as I expect. ``` immutable int x = 10; int* px = cast(int*)&x; *px = 9; writeln(x); ``` It prints 10, where I expected 9. This is on Windows. I'm curious if anyone knows why it happens.
Re: BidirectionalRange switching direction
On Wednesday, 23 September 2015 at 02:10:22 UTC, Tofu Ninja wrote: Trying to implement a bi directional range and it is slightly unclear what the semantics are supposed to be and just wanted some clarification. Are bidirectional ranges supposed to be able to support switching direction mid iteration? Like if I do popFront popFront popBack should that be equal to just a single popFront? Or once you start on a direction should switching be considered an error? Or is popFront and popBack supposed to consume from both ends of the range and the range is empty when they meet? -tofu The last one. E.g. for arrays (except narrow strings... ugh) auto popFront(T)(ref T[] a) { a = a[1 .. $]; } auto popBack(T)(ref T[] a) { a = a[0 .. $-1]; }
BidirectionalRange switching direction
Trying to implement a bi directional range and it is slightly unclear what the semantics are supposed to be and just wanted some clarification. Are bidirectional ranges supposed to be able to support switching direction mid iteration? Like if I do popFront popFront popBack should that be equal to just a single popFront? Or once you start on a direction should switching be considered an error? Or is popFront and popBack supposed to consume from both ends of the range and the range is empty when they meet? -tofu
How to setup mono-D for shared libraries?
How do I setup mono-D for creating shared libraries and including them into other projects? When I drag the .d files to create the library from, which is not my own, I get undefined references. I have the lib files, which are a bunch of separate libs, that I want to include into one big lib. Once that's done I want to include that lib into another project. I'd rather not modify si.ini. Are there any tutorials for getting started with Mono-D? (setup, not coding)
Re: Template detection
On Tuesday, 22 September 2015 at 16:11:59 UTC, Alexandru Ermicioi wrote: Thx. Didn't know that there is such trait available. On page http://dlang.org/traits.html it's not present. Yeah, it's undocumented for some reason. Somebody must've forgot to make a corresponding doc pull request I suppose.
Re: Debugging D shared libraries
Am Tue, 22 Sep 2015 14:40:43 + schrieb John Colvin : > On Tuesday, 22 September 2015 at 14:37:11 UTC, Russel Winder > wrote: > > On Sun, 2015-09-20 at 17:47 +0200, Johannes Pfau via > > Digitalmars-d -learn wrote: > >> [...] > > […] > >> [...] > > > > Debian Jessie is far too out of date to be useful. I'm on > > Debian Sid > > (still quite old), and Fedora Rawhide (not quite so old). > > > > Sadly GDC on Debian Sid tells me 5.2.1 20150911 which may well > > tell Iain which DMD is being used, but I haven't a clue. :-) > > > > […] > > > > The real problem using GDC is: > > > > gdc -I. -O3 -fPIC -c -o processAll_library_d.o > > processAll_library_d.d > > /usr/include/d/core/stdc/config.d:28:3: error: static if > > conditional > > cannot be at global scope > >static if( (void*).sizeof > int.sizeof ) > >^ > > > > I haven't had chance to sit down and see if this is reasonable > > or not. > > seeing as it's an error in core.stdc.config, I'd say it's > definitely not reasonable It's indeed strange. @Russel Winder if you can reproduce this with the latest GDC* please file a bug report. Even the error message doesn't make sense: static if works fine at global scope, AFAIK. * you could use the latest binaries from http://gdcproject.org/downloads
Re: Template detection
On Tuesday, 22 September 2015 at 15:37:32 UTC, Meta wrote: On Sunday, 13 September 2015 at 08:26:55 UTC, Alexandru Ermicioi wrote: Hello, Given: class SomeClass { public { void someSimpleMethod() {} template setOfTemplatedMethods(Type) { void templatedMethodOne() {} void templatedMethodTwo() {} } } } Is there a way to detect at compile time if a member of class/struct is a template? (in the example above, if setOfTemplatedMethods is a template). You can use __traits(isTemplate, ). Thx. Didn't know that there is such trait available. On page http://dlang.org/traits.html it's not present.
Re: Template detection
On Sunday, 13 September 2015 at 08:26:55 UTC, Alexandru Ermicioi wrote: Hello, Given: class SomeClass { public { void someSimpleMethod() {} template setOfTemplatedMethods(Type) { void templatedMethodOne() {} void templatedMethodTwo() {} } } } Is there a way to detect at compile time if a member of class/struct is a template? (in the example above, if setOfTemplatedMethods is a template). You can use __traits(isTemplate, ).
Re: Debugging D shared libraries
On Tuesday, 22 September 2015 at 14:37:11 UTC, Russel Winder wrote: On Sun, 2015-09-20 at 17:47 +0200, Johannes Pfau via Digitalmars-d -learn wrote: [...] […] [...] Debian Jessie is far too out of date to be useful. I'm on Debian Sid (still quite old), and Fedora Rawhide (not quite so old). Sadly GDC on Debian Sid tells me 5.2.1 20150911 which may well tell Iain which DMD is being used, but I haven't a clue. :-) […] The real problem using GDC is: gdc -I. -O3 -fPIC -c -o processAll_library_d.o processAll_library_d.d /usr/include/d/core/stdc/config.d:28:3: error: static if conditional cannot be at global scope static if( (void*).sizeof > int.sizeof ) ^ I haven't had chance to sit down and see if this is reasonable or not. seeing as it's an error in core.stdc.config, I'd say it's definitely not reasonable
Re: Debugging D shared libraries
On Sun, 2015-09-20 at 07:49 +, rom via Digitalmars-d-learn wrote: > […] > > works entirely fine. However the "parallel" code: > > > > extern(C) > > double parallel(const int n, const double delta) { > > Runtime.initialize(); > > const pi = 4.0 * delta * taskPool.reduce!"a + b"( > > map!((int i){ immutable x = (i - 0.5) * delta; return > > 1.0 / (1.0 + x * x); })(iota(1, n + 1))); > > Runtime.terminate(); > > return pi; > > } > > […] > > Isn't it simply that when doing some work asynchronously, as with > task pool, work is being done in other threads than the main. All > the while, you're killing the Runtime. The fact that when > removing Runtime.terminate makes the code work might support > that explanation. I am not sure that can be the case per se as reduce only uses threads internally, the task pool operations should be complete by the time pi is initialized. On the other hand there might be a lock contention between a quiescent default task pool and the terminate code. The code is now moved on a bit from the above, and it works sufficient for the task at hand. This isn't production code so it doesn't have to be quite as good and correct as maybe it should be. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Debugging D shared libraries
On Sun, 2015-09-20 at 17:49 +0200, Johannes Pfau via Digitalmars-d -learn wrote: > […] > > Just realized this thread is titled "Debugging D shared libraries" ; > -) > GDC does not yet support shared libraries. Conversely I thought it did due to the GCC toolchain thingy. I'm using DMD and LDC just now so I have no actual data. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Debugging D shared libraries
On Sun, 2015-09-20 at 17:47 +0200, Johannes Pfau via Digitalmars-d -learn wrote: > Am Sat, 19 Sep 2015 17:41:41 +0100 > […] > > Have you tried using a newer GDC version? The debian jessie version > probably uses the 2.064.2 frontend. Debian Jessie is far too out of date to be useful. I'm on Debian Sid (still quite old), and Fedora Rawhide (not quite so old). Sadly GDC on Debian Sid tells me 5.2.1 20150911 which may well tell Iain which DMD is being used, but I haven't a clue. :-) […] The real problem using GDC is: gdc -I. -O3 -fPIC -c -o processAll_library_d.o processAll_library_d.d /usr/include/d/core/stdc/config.d:28:3: error: static if conditional cannot be at global scope static if( (void*).sizeof > int.sizeof ) ^ I haven't had chance to sit down and see if this is reasonable or not. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Cameleon: Stricter Alternative Implementation of VariantN
On Tuesday, 22 September 2015 at 12:54:47 UTC, Kagamin wrote: You can generate a union from allowed types, it will make copies type safe too, sort of set!(staticIndexOf(T, AllowedTypes))(rhs)... hmm... can it be an overload? I believe there is a trait somewhere that figures out the maximum alignment needed for a set/union of types. I think Walter spoke about in a DConf lecture some time ago.
Re: foreach automoatic counter?
On 9/21/15 6:49 PM, Jonathan M Davis via Digitalmars-d-learn wrote: In general though, if you want a counter for the range that you're indexing, then you can use lockstep to wrap the range, and then when you use it in foreach, you get the count and the element: http://dlang.org/phobos/std_range.html#.lockstep As Justin Whear pointed out, enumerate is better when you have one range. -Steve
Re: Cameleon: Stricter Alternative Implementation of VariantN
You can generate a union from allowed types, it will make copies type safe too, sort of set!(staticIndexOf(T, AllowedTypes))(rhs)... hmm... can it be an overload?
Re: Cameleon: Stricter Alternative Implementation of VariantN
On Tuesday, 22 September 2015 at 12:47:31 UTC, Per Nordlöw wrote: How does the GC know if the data block contains a reference (pointer) or value type? Does it try to follow that pointer either way!? If so when does this memory scanning occurr?
Re: Cameleon: Stricter Alternative Implementation of VariantN
On Tuesday, 22 September 2015 at 09:57:58 UTC, Kagamin wrote: Make sure your struct is always sizeof(void*)-aligned. Could that be automatically enforced somehow based on the contents of AllowedTypes?
Re: Cameleon: Stricter Alternative Implementation of VariantN
On Tuesday, 22 September 2015 at 09:57:58 UTC, Kagamin wrote: - Do I have to call some GC-logic in order to make the GC aware of the new string-reference in `opAssign`? Make sure your struct is always sizeof(void*)-aligned. How does the GC know if the data block contains a reference (pointer) or value type? Does it try to follow that pointer either way!?
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Tuesday, 22 September 2015 at 09:38:12 UTC, thedeemon wrote: I think they don't. Generated .exe seems to depend only on kernel32.dll and shell32.dll, i.e. things users already have. Great then.
Re: Template detection
On Sunday, 13 September 2015 at 09:29:13 UTC, Enamex wrote: On Sunday, 13 September 2015 at 08:26:55 UTC, Alexandru Ermicioi wrote: Hello, Given: class SomeClass { public { void someSimpleMethod() {} template setOfTemplatedMethods(Type) { void templatedMethodOne() {} void templatedMethodTwo() {} } } } Is there a way to detect at compile time if a member of class/struct is a template? (in the example above, if setOfTemplatedMethods is a template). There's this: http://stackoverflow.com/questions/5483381/test-if-an-alias-is-a-template-in-d-2-0 and it should work with 'member templates' OK. Thx for the provided link. I've tried to implement version from the stackoverflow answer, and run against tests provided in another answer to the question in link, and failed. With dmd version 2.067.1 this implementation fails at static assert(! isTemplate!(FooS!int.func!float) ); static assert(! isTemplate!(FooS!int.bar) ); for .func it requires "this" (an value of type FooS, or isTemplate fails to instantiate). and for .bar it just fails (isTemplate detects it as a template). I've found another way to detect if a symbol is a template. The idea is that for a not instantiated template you can get with allMembers trait the list of members in template, but you can't access them using getMembers trait since the template is not instantiated yet. So if there is a symbol that has members which cannot be accessed using getMember (generates an error) then this is a template! template allMembers(alias Type) { alias allMembers = TypeTuple!(__traits(allMembers, Type)); } template anyAccessible(alias Container, T...) { static if (T.length > 1) { enum bool anyAccessible = anyAccessible!(Container, T[0 .. $ / 2]) || anyAccessible!(Container, T[$ / 2 .. $]); } else static if (T.length == 1) { enum bool anyAccessible = __traits(compiles, getMember!(Container, T[0])); } else { enum bool anyAccessible = false; } } template isTemplate(alias T) { static if ( // check if symbol has members __traits(compiles, TypeTuple!(__traits(allMembers, T))) && !T.stringof.startsWith("module ", "package ") ) { enum bool isTemplate = (allMembers!(T).length > 0) && !anyAccessible!(T, allMembers!T); } else { enum bool isTemplate = false; } } It passes almost all tests except for: static assert(! isTemplate!((int x){return x;}) ); static assert(! isTemplate!(std) ); static assert(! isTemplate!(core) ); I don't know how but in this cases, compiler attempts to parse true branch of static if, even if the expression in static if is false. For lamda function allMembers trait fails to get the members and an error is created by compiler. For std, and core packages isTemplate evaluates to true even if expression from static if is false. Is such behavior of static if correct (tested also with ldc compiler, same results)? If there are other test cases, would be glad if they are posted here (to improve the accuracy of template detection). Tests are: struct FooS(T) { struct Inner {} struct Inner2(string U="!(") {} int func(U)() { return 0; } int bar; } FooS!int foo; class FooC { int x; } union FooU { int x;} enum FooE { x } interface FooI { int x(); } template FooT(T) { struct Inner {} struct Inner2(string U="!(") {} int func(U)() { return 0; } int bar; } static assert(! isTemplate!0 ); static assert(! isTemplate!"0" ); static assert(! isTemplate!0.0f ); static assert(! isTemplate!'0' ); static assert(! isTemplate!'!' ); static assert(! isTemplate!"module std.stdio" ); static assert(! isTemplate!null ); static assert(! isTemplate!true ); static assert(! isTemplate!__FILE__ ); static assert(! isTemplate!__LINE__ ); static assert(! isTemplate!([]) ); static assert( isTemplate!FooS ); static assert(! isTemplate!(FooS!int) ); static assert( isTemplate!(FooS!int.func) ); static assert(! isTemplate!(FooS!int.func!float) ); static assert(! isTemplate!(FooS!int.bar) ); static assert(! isTemplate!(FooS!int.Inner) ); static assert( isTemplate!(FooS!int.Inner2) ); static assert(! isTemplate!(FooS!int.Inner2!"?") ); static assert( isTemplate!FooT ); static assert(! isTemplate!(FooT!int) ); static assert( isTemplate!(FooT!int.func) ); static assert(! isTemplate!(FooT!int.func!float) ); static assert(! isTemplate!(FooT!int.bar) ); static assert(! isTemplate!(FooT!int.Inner) ); static assert( isTemplate!(FooT!int.Inner2) ); static assert(! isTemplate!(FooT!int.Inner2!"?") ); static assert(! isTemplate!foo ); static assert( isTemplate!(foo.func) ); static assert( isTemplate!isTemplate ); static assert(! isTemplate!(isTemplate!isTemplate) ); static assert(! isTemplate!FooC ); static assert(! isTemplate!FooU ); static assert(! isTemplate!FooE ); static assert(! isTemplate!FooI ); static assert(! isTemplate!((int x){retur
Re: Has anyone created a D wrapper for wbemuuid.lib
The bindings are translated from mingw headers, and mingw doesn't supply libraries with precompiled GUIDs, only functions. But bindings for GUIDs are pretty simple: extern extern(System) CLSID CLSID_SWbemLocator; Just copy the names you want.
Re: Has anyone created a D wrapper for wbemuuid.lib
On Tuesday, 22 September 2015 at 10:03:52 UTC, Thomas Mader wrote: Do I miss something? Does anyone have wrapped this lib? This was also asked on stackoverflow some time ago. [1] Wonder if something happend since then. [1] http://stackoverflow.com/questions/24051606/can-i-use-routines-from-comdef-h-wbemidl-h-etc-in-d
Has anyone created a D wrapper for wbemuuid.lib
I looked at some of the windows API wrapper projects for D on github [1][2], but none of them seems to have wrapped wbemuuid.lib right now. Do I miss something? Does anyone have wrapped this lib? Thomas [1] http://code.dlang.org/packages/windows-headers [2] https://github.com/smjgordon/bindings/tree/master/win32
Re: Cameleon: Stricter Alternative Implementation of VariantN
On Monday, 21 September 2015 at 13:42:14 UTC, Nordlöw wrote: Questions: - Is the logic of opAssign and get ok for string? - How does the inner workings of the GC harmonize with my calls to `memcpy` in `opAssign()` here https://github.com/nordlow/justd/blob/master/cameleon.d#L80 That line won't compile, so don't be afraid of its behavior. - Do I have to call some GC-logic in order to make the GC aware of the new string-reference in `opAssign`? Make sure your struct is always sizeof(void*)-aligned.
Re: Do users need to install VS runtime redistributable if linking with Microsoft linker?
On Monday, 21 September 2015 at 15:00:24 UTC, ponce wrote: All in the title. DMD 64-bit links with the VS linker. Do users need to install the VS redistributable libraries? I think they don't. Generated .exe seems to depend only on kernel32.dll and shell32.dll, i.e. things users already have.
Re: Weird behaviour with File.eof
On Sunday, 20 September 2015 at 20:17:37 UTC, Dandyvica wrote: My file is made of 10 lines: cat numbers.txt 1 2 3 4 5 6 7 8 9 10 ╰─$ wc -l numbers.txt CR/LF can be interpreted as line _dividers_, so if you have CR or CR/LF at the end of line 10, really here is line 11 which is empty. Remove end of line symbols at line 10 and you will have expected output: before readln eof=false, line=<1>, after readln eof=false before readln eof=false, line=<2>, after readln eof=false before readln eof=false, line=<3>, after readln eof=false before readln eof=false, line=<4>, after readln eof=false before readln eof=false, line=<5>, after readln eof=false before readln eof=false, line=<6>, after readln eof=false before readln eof=false, line=<7>, after readln eof=false before readln eof=false, line=<8>, after readln eof=false before readln eof=false, line=<9>, after readln eof=false before readln eof=false, line=<10>, after readln eof=true p.s. it's good style to check input parameters, even for most simple cases.