Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Steven Schveighoffer
On Thu, 27 May 2010 18:41:19 -0400, bearophile wrote: Thank you Steven for your explanations, I have done similar things in C and D, but I didn't understand what you meant. A is always put first, that way, a pointer to a B can always be used as a pointer to an A.< Are you sure C specs

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Thank you Steven for your explanations, I have done similar things in C and D, but I didn't understand what you meant. >A is always put first, that way, a pointer to a B can always be used as a >pointer to an A.< Are you sure C specs say doing this leads to defined behaviour? (Recently from a d

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Ali: > For what it's worth, here is a code that uses 'dup' instead of 'copy'. Oh, right. I have forgotten to say this to the OP. In D it's better to name it dup instead of copy. >I know this is not the same thing; but I find this more intuitive:< I agree, it's better for D. > A dup() co

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Steven Schveighoffer
On Thu, 27 May 2010 17:47:20 -0400, bearophile wrote: Steven Schveighoffer: I have hoped that at some point, structs can be auto-composed, without a vtable, but you still have to do this manually. I don't understand what you mean here :-) I mean simple inheritance. In C, there has alway

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Ali Çehreli
bearophile wrote: Larry Luther: Ok, I've added -w to compilation commands and I've switched back to pure text.< Good :-) What am I missing?< I have modified a bit your D code like this, to have something with a main() that runs: import std.c.stdio: puts; class A { int x, y;

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Steven Schveighoffer: > I have hoped that at some point, structs can be auto-composed, > without a vtable, but you still have to do this manually. I don't understand what you mean here :-) Bye, bearophile

Re: Handy templates

2010-05-27 Thread Philippe Sigaud
>On Thu, May 27, 2010 at 01:00, Simen kjaeraas wrote: >Here's a collection of templates I have created and use often. >Some of these may be fit for inclusion in Phobos, others maybe not as much. >Please critique, and post your own indispensable snippets. Hey, cool idea ! Do you have a site to put

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Steven Schveighoffer
On Thu, 27 May 2010 17:04:35 -0400, Larry Luther wrote: "bearophile" wrote in message news:ht4krg$17l...@digitalmars.com... | On the base of your long experience do you like D so far? There are many things that I like and I strongly agree with the failings of C++ mentioned in the docs. I d

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Larry Luther: > There are many things that I like and I strongly agree with the failings > of C++ mentioned in the docs. D is designed by people that have a good experience of C++, but while probably D avoids some C++ problems, it surely introduces a number of new issues :-) > I don't like the

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Larry Luther
"bearophile" wrote in message news:ht4krg$17l...@digitalmars.com... | On the base of your long experience do you like D so far? There are many things that I like and I strongly agree with the failings of C++ mentioned in the docs. I don't like the asymmetry between structs and classes. I don't

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
See: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=110554

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Larry Luther: >Ok, I've added -w to compilation commands and I've switched back to pure text.< Good :-) >What am I missing?< I have modified a bit your D code like this, to have something with a main() that runs: import std.c.stdio: puts; class A { int x, y; void copy(const A a) {

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread bearophile
Larry Luther: I'm nonplussed. Could you expand on why D class instances don't need to copy their contents and instances of D structs do? While migrating C++ code to D I've had to convert "struct"s to "class"es because of the need for inheritance. Why would the need to copy an instance's conte

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Larry Luther
"bearophile" wrote in message news:ht4g3r$vu...@digitalmars.com... | Larry Luther: | | > I did not get an error when building and running with DMD 2.042: | | I am using dmd v2.046, and I have taken the good habit of compiling with -w (warnings on). | It seems this error I see is a blocking warni

Re: Finding and invoking struct destructors in D2

2010-05-27 Thread Don
div0 wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Pillsy wrote: Hi, all, I was wondering if there's any way to determine at compile time whether a struct has a (non-trivial) destructor associated with it, and whether there's any way to call that destructor without using the delete oper

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Larry Luther
"bearophile" wrote in message news:ht42el$6c...@digitalmars.com... ... | There is no standard way to do this. In general you don't need to copy classes or their contents, because they are on the heap and managed by the GC. I'm nonplussed. Could you expand on why D class instances don't nee

Re: Newbie: copy, assignment of class instances

2010-05-27 Thread Larry Luther
Thank you, I had no idea that scope was doing this. I thought that when the docs said that it was being allocated on the stack that I was getting "struct" like behavior. "Simen kjaeraas" wrote in message news:op.vc0qlpjovxi...@biotronic-pc.home... | Larry Luther wrote: | | > | > scope B | >

Re: Finding and invoking struct destructors in D2

2010-05-27 Thread Pillsy
== Quote from div0 (d...@users.sourceforge.net)'s article: [...] > Most important is this one, which scuppers any change of doing > a shared ptr like struct: > http://d.puremagic.com/issues/show_bug.cgi?id=3516 Yeah, that basically kills the idea until the bug is fixed. :( Once it is, I think a

Re: Finding and invoking struct destructors in D2

2010-05-27 Thread div0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Pillsy wrote: > Hi, all, > > I was wondering if there's any way to determine at compile time > whether a struct has a (non-trivial) destructor associated with it, > and whether there's any way to call that destructor without using > the delete operato

Finding and invoking struct destructors in D2

2010-05-27 Thread Pillsy
Hi, all, I was wondering if there's any way to determine at compile time whether a struct has a (non-trivial) destructor associated with it, and whether there's any way to call that destructor without using the delete operator. It seems like being able to do these two things would allow you to mak

Re: problem with reduce on array of Tuples

2010-05-27 Thread Pelle
This has nothing to do with the tuples, I think. test2.d: import std.algorithm; void main() { map!((int x){return x+1;})([1,2,3,4,5]); } pp ~/dee% rdmd test2.d test2.d(4): Error: delegate std.algorithm.__dgliteral1 cannot access frame of function __dgliteral1 test2.d(4): Error: template

problem with reduce on array of Tuples

2010-05-27 Thread Adrian Matoga
The following code fails to compile: double sim(Document doc, string query) { alias Tuple!(double, "wij", double, "wiq") Weights; Document q = Document.fromString(query); Weights[] wi; foreach (s; StrFilt(query)) wi ~= Weights(doc.termFreq(s) * i