Re: Template constructor in a non-template struct.

2015-02-14 Thread ChrisG via Digitalmars-d-learn
On Monday, 9 February 2015 at 09:52:13 UTC, Marc Schütz wrote: You could also hide the ugly __ctor() call behind a nicely named factory method. Yes, that's pretty much what I ended up doing. Added a couple static member functions like: static Boring CreateWithOption1(args); static Boring

Re: Explicit Interface Implementation

2015-02-14 Thread Ali Çehreli via Digitalmars-d-learn
On 02/14/2015 12:13 PM, Adam D. Ruppe wrote: On Saturday, 14 February 2015 at 20:08:09 UTC, Ali Çehreli wrote: int foo() { return 42; } the difference is C# also allows you to implement A.foo separately from B.foo. I don't think D allows that. Yeah, I obviously read too

Re: The best way to compare floating point values.

2015-02-14 Thread Jack Applegame via Digitalmars-d-learn
On Saturday, 14 February 2015 at 10:23:48 UTC, Gary Willoughby wrote: I wrote a similar function here: https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L42 or using an epsilon value: https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L134 I

Re: std.conv.to purity

2015-02-14 Thread ketmar via Digitalmars-d-learn
On Sat, 14 Feb 2015 11:29:28 +, Jack Applegame wrote: why std.conv.to is not pure? string foo(real v) pure { return v.to!string; } // Error: pure function 'foo' cannot call impure function 'std.conv.to!string.to!(real).to' 'cause float-string conversion is damned hard task. to perform

Re: The best way to compare floating point values.

2015-02-14 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 14 February 2015 at 09:37:05 UTC, Jack Applegame wrote: I wrote this function for comparing two floating point values: import std.math; import std.traits; bool isEqual(T)(T v1, T v2) if(isFloatingPoint!T) { return T.mant_dig - feqrel(v1, v2) 2; } What do you think about it?

std.conv.to purity

2015-02-14 Thread Jack Applegame via Digitalmars-d-learn
why std.conv.to is not pure? string foo(real v) pure { return v.to!string; } // Error: pure function 'foo' cannot call impure function 'std.conv.to!string.to!(real).to'

Re: The best way to compare floating point values.

2015-02-14 Thread Ivan Kazmenko via Digitalmars-d-learn
There is an approxEqual in std.math, in addition in feqrel: http://dlang.org/phobos/std_math.html#.approxEqual It takes maximum absolute and relative difference as arguments.

The best way to compare floating point values.

2015-02-14 Thread Jack Applegame via Digitalmars-d-learn
I wrote this function for comparing two floating point values: import std.math; import std.traits; bool isEqual(T)(T v1, T v2) if(isFloatingPoint!T) { return T.mant_dig - feqrel(v1, v2) 2; } What do you think about it?

Re: What is the Correct way to Malloc in @nogc section?

2015-02-14 Thread ketmar via Digitalmars-d-learn
On Sat, 14 Feb 2015 07:59:51 +, weaselcat wrote: how smart pointers can help here? they don't magically hiding all the low-level mechanics. The file he was referring to was a smart pointer implementation. *one* of the files. signature.asc Description: PGP signature

Re: dmd-2.067.0-b1

2015-02-14 Thread RuZzz via Digitalmars-d-learn
It is your profile? http://www.cyberforum.ru/members/491746.html

Re: How to make a Currency class from std.BigInt?

2015-02-14 Thread RuZzz via Digitalmars-d-learn
The next version https://bpaste.net/show/dc3c5f10f2ca I use https://github.com/dsimcha/Rational/blob/master/rational.d I want to do it: auto c = new Currencies!Rational.rational.Rational!(BigInt); where Rational.rational.Rational it is std.rational.Rational I get the error: Error: template

Explicit Interface Implementation

2015-02-14 Thread ref2401 via Digitalmars-d-learn
Does D provide a way for explicit interface implementation? [C#] https://msdn.microsoft.com/en-us/library/ms173157.aspx

Re: Explicit Interface Implementation

2015-02-14 Thread Ivan Timokhin via Digitalmars-d-learn
ref2401 wrote: Does D provide a way for explicit interface implementation? [C#] https://msdn.microsoft.com/en-us/library/ms173157.aspx Not exactly, but you may try something like this: interface A { void foo(); } interface B { void foo(); } class C : A { class Nested : B {

Re: std.conv.to purity

2015-02-14 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 14 February 2015 at 12:24:51 UTC, ketmar wrote: On Sat, 14 Feb 2015 11:29:28 +, Jack Applegame wrote: why std.conv.to is not pure? string foo(real v) pure { return v.to!string; } // Error: pure function 'foo' cannot call impure function 'std.conv.to!string.to!(real).to'

Re: Explicit Interface Implementation

2015-02-14 Thread Ali Çehreli via Digitalmars-d-learn
On 02/14/2015 09:19 AM, ref2401 wrote: Does D provide a way for explicit interface implementation? [C#] https://msdn.microsoft.com/en-us/library/ms173157.aspx Apparently, yes: interface A { int foo(); } interface B { int foo(); } class C : A, B { int foo() { return

Re: Explicit Interface Implementation

2015-02-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 14 February 2015 at 20:08:09 UTC, Ali Çehreli wrote: int foo() { return 42; } the difference is C# also allows you to implement A.foo separately from B.foo. I don't think D allows that. You can call a specific interface at the usage site, but implementing

Re: std.conv.to purity

2015-02-14 Thread ketmar via Digitalmars-d-learn
On Sat, 14 Feb 2015 19:59:58 +, Gary Willoughby wrote: On Saturday, 14 February 2015 at 12:24:51 UTC, ketmar wrote: On Sat, 14 Feb 2015 11:29:28 +, Jack Applegame wrote: why std.conv.to is not pure? string foo(real v) pure { return v.to!string; } // Error: pure function 'foo'

Re: std.conv.to purity

2015-02-14 Thread Brad Roberts via Digitalmars-d-learn
While snprintf might be one thing that provides to be an interesting obstacle, the better answer to why std.conv.to isnt pure is that no one has invested the time to work through issues like that to make it so. It _should_ be pure. On 2/14/2015 12:32 PM, ketmar via Digitalmars-d-learn wrote:

foreach filter by cast

2015-02-14 Thread karl via Digitalmars-d-learn
Is there a brief way to iterate an array of objects, and process only objects of certain type (in either two ways, with/without inheritance)? foreach(p; obj.children){ // KObj[] children DPFile dfile = cast(DPFile)p; if(!dfile)continue;

Re: foreach filter by cast

2015-02-14 Thread karl via Digitalmars-d-learn
I found a solution I like a lot, with templated opApply: class Cont{ Thing[] kids; int opApply(T)(int delegate(ref T) dg){ int result = 0; for (int i = 0; i kids.length; i++){ T t = cast(T)kids[i];

Re: What is the Correct way to Malloc in @nogc section?

2015-02-14 Thread weaselcat via Digitalmars-d-learn
On Saturday, 14 February 2015 at 06:38:19 UTC, ketmar wrote: On Sat, 14 Feb 2015 00:57:33 +, weaselcat wrote: On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-14 Thread via Digitalmars-d-learn
On Friday, 13 February 2015 at 22:39:10 UTC, bearophile wrote: H. S. Teoh: So it could be called ilog2? Perhaps floorIlog2? Isn't ilog2 a different function? Bye, bearophile I think the naming depends on use context, so it is reasonable to land on different names in different domains.

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-02-14 Thread via Digitalmars-d-learn
On Saturday, 14 February 2015 at 08:01:27 UTC, Ola Fosheim Grøstad wrote: I think the naming depends on use context, so it is reasonable to land on different names in different domains. Maybe the standard notation should be ffs(x): Oops, I meant fls(x)... I just woke up :-P. It is a bad name