Re: Opt-out polymorphism?

2011-02-13 Thread Steven Wawryk
Generalizing the original question to *all* member functions, it can be desirable to to have non-polymorphic inheritance, at least not *runtime* polymorphic. I get the impression that it wouldn't be used much by most people who post on these newsgroups, but there are application areas it can

Re: Opt-out polymorphism?

2011-02-13 Thread Jonathan M Davis
On Sunday 13 February 2011 17:40:39 bearophile wrote: > Jonathan M Davis: > > And honestly, in most cases, I think that what you're trying to do is > > just plain begging for bugs. It is kind of cool that C# found a > > relatively clean way to deal with it, but I honestly don't know what > > it's u

Re: Opt-out polymorphism?

2011-02-13 Thread bearophile
Jonathan M Davis: > And honestly, in most cases, I think that what you're trying to do is just > plain > begging for bugs. It is kind of cool that C# found a relatively clean way to > deal with it, but I honestly don't know what it's useful for. I'd be worried > about a program which overrode

Re: Opt-out polymorphism?

2011-02-13 Thread Jonathan M Davis
On Sunday 13 February 2011 13:34:04 Sean Eskapp wrote: > Is there a way to specify that a function is nonvirtual, but can still be > "overriden" in base classes? e.g. > > class A > { > void foo() > { > writeln("A"); > } > } > > class B : A > { > void foo() > { >

Re: traits: how to split parametrized type into basic type and parameters

2011-02-13 Thread Martin Kinkelin
I realize a parametrized constructor would be a better option: this(T2)(const(Vector!(d,T2)) rhs) if (isNumeric!T2) { ... } // e.g., auto i4 = int4(f4); but I'd still prefer the casting syntax if possible.

traits: how to split parametrized type into basic type and parameters

2011-02-13 Thread Martin Kinkelin
Hi, I'm implementing a generic Vector!(uint d, T) struct (wrapping a T[d] array). For readability: alias Vector!(4u,float) float4; alias Vector!(4u,int) int4; I'd like to be able to cast a float4 variable explicitly to an int4 (component-wise casting): auto f4 = float4(1,2,3,4); auto i4 = cast(

Read non-UTF8 file

2011-02-13 Thread Nrgyzer
Hey guys, I've the following source: module filereader; import std.file; import std.stdio : writeln; void main(string[] args) { File f = new File("myFile.ext", FileMode.In); while(!f.eof()) { writeln(convertToUTF8(f.readLine())); } f.close(); } s

Opt-out polymorphism?

2011-02-13 Thread Sean Eskapp
Is there a way to specify that a function is nonvirtual, but can still be "overriden" in base classes? e.g. class A { void foo() { writeln("A"); } } class B : A { void foo() { writeln("B"); } } void main() { (new A).foo(); (new B).foo(); } Should

Re: Double-dispatch

2011-02-13 Thread Sean Eskapp
== Quote from bearophile (bearophileh...@lycos.com)'s article > Sean Eskapp: > > Is there a nicer way to do this in D, or am I stuck with the same thing? > Andrei has recently said no one needs double dispatch (in D) :-) So Andrei > will be interested in your use case. > Bye, > bearophile The age

Re: Double-dispatch

2011-02-13 Thread bearophile
Sean Eskapp: > Is there a nicer way to do this in D, or am I stuck with the same thing? Andrei has recently said no one needs double dispatch (in D) :-) So Andrei will be interested in your use case. Bye, bearophile

produce standard notation for strings

2011-02-13 Thread spir
Hello, I need to write one or more tool functions that produce standard notation for strings. Something like python's repr(s). For instance: `abc def "ghi" jkl` --> "abc\ndef\t\"ghi\" jkl" which, fed back into D code, reproduces the original string. I have actually several formats in mind,

Re: Double-dispatch

2011-02-13 Thread Lutger Blijdestijn
Sean Eskapp wrote: > I remember in C++, I had to do double-dispatch using the visitor pattern. > This is cumbersome, just because each subclass has to have the exact same > singly-dispatched code that looks like: > > void dispatch(Base& other) > { >other.dispatch(*this); > } > > Is there a n

Re: Double-dispatch

2011-02-13 Thread Simen kjaeraas
Sean Eskapp wrote: I remember in C++, I had to do double-dispatch using the visitor pattern. This is cumbersome, just because each subclass has to have the exact same singly-dispatched code that looks like: void dispatch(Base& other) { other.dispatch(*this); } Is there a nicer way to do

Double-dispatch

2011-02-13 Thread Sean Eskapp
I remember in C++, I had to do double-dispatch using the visitor pattern. This is cumbersome, just because each subclass has to have the exact same singly-dispatched code that looks like: void dispatch(Base& other) { other.dispatch(*this); } Is there a nicer way to do this in D, or am I stuck

Re: BigInt problem

2011-02-13 Thread bearophile
tsukikage: > For curiosity, would you explain/guess a possible reason for that? I leave the answer to Don, I don't know the internals of D BigInts. Multi-precision integers are basic bricks used to build many other programs. How can you be sure they don't contain bugs that break your heavy nume

Re: using a binary tree container

2011-02-13 Thread Mafi
Am 12.02.2011 00:02, schrieb spir: On 02/11/2011 10:33 PM, Mafi wrote: I allways try to import 'algorythm' because of the german word 'Algorythmus'. When this happend for the first time, I spent about five minutes to find out what's wrong. It is spelled Algorithmus in German, no ypsilon ;-) h

Error: this for ~this needs to be type foo not type foo[1u][1u]

2011-02-13 Thread d coder
Greetings I am getting this error when I am instantiating a struct array with a single element inside another class and only if there is the destructor for the struct is explicitly defined. Is it a known error? Here is a minimized snippet that gives error: $ rdmd --main -unittest test.d Error: t

Re: using a binary tree container

2011-02-13 Thread Lutger Blijdestijn
Dominic Jones wrote: > Hello, > > I have a list of strings and I want to determine whether or not a > particular string in the is in that list. Assuming I should store the list > of strings in a binary tree to facilitate fast searching, I had a look at > the std.container documentation and found

Re: BigInt problem

2011-02-13 Thread tsukikage
For curiosity, would you explain/guess a possible reason for that? Thanks! bearophile wrote: tsukikage: Is it my program bug or bigint broken? http://d.puremagic.com/issues/show_bug.cgi?id=5568 Bye, bearophile

Re: Number of references to a Class Object

2011-02-13 Thread d coder
> However, it's not generally an issue, because you shouldn't normally be > keeping > references around for stuff that isn't used anymore. The garbage collector is > smart enough to deal with circular references and the like, so the biggest > cases > where you'd normally need weak references aren

Re: using a binary tree container

2011-02-13 Thread spir
On 02/13/2011 01:18 AM, Ali Çehreli wrote: On 02/11/2011 04:55 PM, spir wrote: Also, trees are not always O(logN): tries () are O(1) for access, relative to number of elements, in fact their search is not related to that factor, just like hash table instead to the length of keys (O(log(leng