Re: Don't expect class destructors to be called at all by the GC

2017-12-22 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 22 December 2017 at 00:09:31 UTC, Mike Franklin wrote: What condition(s) would cause a destructor for an object that is managed by the GC to potentially not be called? Good question. It's true that barring an Error, they should be called by the GC at runtime termination.

Compiler gets confused with ambiguity when `int` matches both `real` and `float`.

2017-12-22 Thread IM via Digitalmars-d-learn
The following expression: import std.math : sqrt; sqrt(400); produces the following compiler error: std.math.sqrt called with argument types (int) matches both: /usr/include/dmd/phobos/std/math.d(1592,7): std.math.sqrt(float x) and: /usr/include/dmd/phobos/std/math.d(1598,6):

Re: why ushort alias casted to int?

2017-12-22 Thread Nathan S. via Digitalmars-d-learn
On Friday, 22 December 2017 at 10:42:28 UTC, crimaniak wrote: Hm, really. ok, I will use the explicit cast, but I don't like it. It's because the C programming language has similar integer promotion rules. That doesn't make it any more convenient if you weren't expecting it but that is the

Re: why ushort alias casted to int?

2017-12-22 Thread ketmar via Digitalmars-d-learn
crimaniak wrote: Both operands are the same type, so as I understand casting to longest type is not needed at all, and longest type here is ushort in any case. What am I doing wrong? it is hidden in specs: all types shorter than int are promoted to int before doing any math.

Re: why ushort alias casted to int?

2017-12-22 Thread crimaniak via Digitalmars-d-learn
On Friday, 22 December 2017 at 10:18:52 UTC, ketmar wrote: crimaniak wrote: Both operands are the same type, so as I understand casting to longest type is not needed at all, and longest type here is ushort in any case. What am I doing wrong? it is hidden in specs: all types shorter than int

why ushort alias casted to int?

2017-12-22 Thread crimaniak via Digitalmars-d-learn
My code: alias MemSize = ushort; struct MemRegion { MemSize start; MemSize length; @property MemSize end() const { return start+length; } } Error: cannot implicitly convert expression `cast(int)this.start + cast(int)this.length` of type `int` to `ushort` Both

Does LDC support profiling at all?

2017-12-22 Thread Chris Katko via Digitalmars-d-learn
DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's using to make those decisions! :) Thanks.

Re: std way to remove multiple indices from an array at once

2017-12-22 Thread aliak via Digitalmars-d-learn
On Thursday, 21 December 2017 at 15:59:44 UTC, Steven Schveighoffer wrote: Here's a similar solution with an actual range: https://run.dlang.io/is/gR3CjF Note, all done lazily. However, the indices must be sorted/unique. -Steve Noice! :D

Re: why ushort alias casted to int?

2017-12-22 Thread Patrick Schluter via Digitalmars-d-learn
On Friday, 22 December 2017 at 10:14:48 UTC, crimaniak wrote: My code: alias MemSize = ushort; struct MemRegion { MemSize start; MemSize length; @property MemSize end() const { return start+length; } } Error: cannot implicitly convert expression `cast(int)this.start +

Re: Version Cygwin

2017-12-22 Thread Anonymouse via Digitalmars-d-learn
On Friday, 22 December 2017 at 03:24:15 UTC, rikki cattermole wrote: You are not using a Cygwin build. It doesn't matter who calls a process, it doesn't change the version's by itself. As far as I know, nobody supports Cygwin like this. I see, thank you.

Re: GC in D and synadard library.

2017-12-22 Thread Kagamin via Digitalmars-d-learn
See also how dplug is implemented https://forum.dlang.org/post/hbmbztydvyfwemfne...@forum.dlang.org

alias to struct method

2017-12-22 Thread Marc via Digitalmars-d-learn
How can I create a alias to a struct method? struct S { string doSomething(int n) { return ""; } } I'd like to do something like this (imaginary code): alias doSomething = S.doSomething; then call it by doSomething(3) I got the following error from this code: Error: need 'this' for

Re: Does LDC support profiling at all?

2017-12-22 Thread Nathan S. via Digitalmars-d-learn
On Friday, 22 December 2017 at 09:52:26 UTC, Chris Katko wrote: DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's

Re: Converting member variables to strings with using reflection from base class

2017-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 22, 2017 at 09:13:31PM +, kerdemdemir via Digitalmars-d-learn wrote: > I want to make a logging function for member variables by using reflection. [...] > class B > { > void Log() > { > auto a = [__traits(derivedMembers, D)]; > foreach(memberName; a) { >

How to I get the dub package version that I want...

2017-12-22 Thread WhatMeWorry via Digitalmars-d-learn
I can compile the derelict-fmod example with dub.json ... "dependencies": { "derelict-util": ">=1.9.1" ... and dub.selections.json ... "versions": { "derelict-util": "2.1.0" ... dub run Fetching derelict-util

Converting member variables to strings with using reflection from base class

2017-12-22 Thread kerdemdemir via Digitalmars-d-learn
I want to make a logging function for member variables by using reflection. import std.stdio; class D : B { override void foo() { a = 4.0; b = 3.0; } double a; double b; } class B { void Log() { auto a = [__traits(derivedMembers, D)];

Parsing string to octal(for umask) at runtime?

2017-12-22 Thread Ryan David Sheasby via Digitalmars-d-learn
Hi. Struggling to figure this out. At the bottom of this page: https://dlang.org/library/std/conv/octal.html is a vague reference to using parse. However, when I use what I would assume to be correct based on this: https://dlang.org/phobos/std_conv.html#.parse.3 and the fact that in the octal

Re: Parsing string to octal(for umask) at runtime?

2017-12-22 Thread Ryan David Sheasby via Digitalmars-d-learn
On Friday, 22 December 2017 at 21:36:20 UTC, Ryan David Sheasby wrote: Hi. Struggling to figure this out. At the bottom of this page: https://dlang.org/library/std/conv/octal.html is a vague reference to using parse. However, when I use what I would assume to be correct based on this:

Re: alias to struct method

2017-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/2017 09:53 AM, Marc wrote: > How can I create a alias to a struct method? > >> struct S { >> string doSomething(int n) { return ""; } >> } > > I'd like to do something like this (imaginary code): > > alias doSomething = S.doSomething; > > then call it by doSomething(3) That can't work

Re: alias to struct method

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Friday, 22 December 2017 at 17:53:34 UTC, Marc wrote: How can I create a alias to a struct method? struct S { string doSomething(int n) { return ""; } } I'd like to do something like this (imaginary code): alias doSomething = S.doSomething; then call it by doSomething(3) I got the

Re: Converting member variables to strings with using reflection from base class

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Friday, 22 December 2017 at 22:09:05 UTC, H. S. Teoh wrote: On Fri, Dec 22, 2017 at 09:13:31PM +, kerdemdemir via Digitalmars-d-learn wrote: I want to make a logging function for member variables by using reflection. [...] class B { void Log() { auto a =

Re: One liner for creating an array filled by a factory method

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Thursday, 21 December 2017 at 21:11:58 UTC, Steven Schveighoffer wrote: On 12/21/17 4:00 PM, kerdemdemir wrote: I have a case like : http://rextester.com/NFS28102 I have a factory method, I am creating some instances given some enums. My question is about : void PushIntoVector(

Re: Don't expect class destructors to be called at all by the GC

2017-12-22 Thread Mengu via Digitalmars-d-learn
On Thursday, 21 December 2017 at 18:45:27 UTC, Adam D. Ruppe wrote: On Thursday, 21 December 2017 at 18:20:19 UTC, H. S. Teoh wrote: When the scoped destruction of structs isn't an option, RefCounted!T seems to be a less evil alternative than an unreliable class dtor. :-/ Alas, RefCounted

Re: Don't expect class destructors to be called at all by the GC

2017-12-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 December 2017 at 23:34:55 UTC, Mengu wrote: i really wonder how Objective-C and Swift is pulling this off. It isn't a fundamental problem, D just can't express it in the existing language (heck, even D, as defined, could do it, the implementation just isn't there.)