digitalmars.D.learn - sort and shared
- Adam Conner-Sax (41/41) Jan 20 2011 The following code:
- Steven Schveighoffer (6/38) Jan 21 2011 This should be fixed in svn. I encountered a very similar issue, and
- Adam Conner-Sax (9/9) Jan 21 2011 Thanks!
- Steven Schveighoffer (6/18) Jan 21 2011 Hm... it's a simple patch. Maybe there is something different I'm not
- Steven Schveighoffer (8/29) Jan 21 2011 Compiled your code and ran it without error (well, got a segfault becaus...
- Adam Conner-Sax (4/4) Jan 23 2011 Thanks.
The following code: import std.algorithm; class Foo { private: int id_; public: shared int id() const { return id_; } } static bool compare(in shared(Foo) a, in shared(Foo) b) { return (a.id() < b.id()); } void main() { shared Foo a,b,c; shared(Foo)[] uFooArray = [a,b,c]; sort!(compare)(uFooArray); } fails to compile with usr/local/src/dmd2/src/phobos/std/conv.d(295): Error: function object.Object.toString () is not callable using argument types () whereas if I just take all the shared away it compiles fine. I imagine that this is somewhere to do with a string function being called on an element of the array and then there's no shared version of that method. Is there a fix? Or a different way to call sort? I can cast away shared for the sort but since in the actual application I have a reason for it, that's a bit worrisome. Thanks! Adam Adam begin 644 test.d M:6UP;W)T('-T9"YA;&=O<FET:&T[" IC;&%S<R!&;V\ "GL*<')I=F%T93H* M("!S=&%T:6, :6YT(&YE>'1?:61?(#T ,#L*("!I;G0 :61?.PH ('1H:7,H M*2![(&ED7R`](&YE>'1?:61?*RL[('T*<'5B;&EC. H ('-H87)E9"!I;G0 M:60H*2!C;VYS="![(')E='5R;B!I9%\[('T*?0H*"G-T871I8R!B;V]L(&-O M;7!A<F4H:6X <VAA<F5D*$9O;RD 82P :6X <VAA<F5D*$9O;RD 8BD "GL* M("!R971U<FX *&$N:60H*2`\(&(N:60H*2D["GT*"G9O:60 ;6%I;B I(`I[ M"B` <VAA<F5D($9O;R!A+&(L8SL*("!S:&%R960H1F]O*5M=('5&;V]!<G)A M>2`](%MA+&(L8UT["B` <V]R="$H8V]M<&%R92DH=49O;T%R<F%Y*3L*?0`` ` end
Jan 20 2011
On Thu, 20 Jan 2011 21:14:06 -0500, Adam Conner-Sax <adam_conner_sax yahoo.com> wrote:The following code: import std.algorithm; class Foo { private: int id_; public: shared int id() const { return id_; } } static bool compare(in shared(Foo) a, in shared(Foo) b) { return (a.id() < b.id()); } void main() { shared Foo a,b,c; shared(Foo)[] uFooArray = [a,b,c]; sort!(compare)(uFooArray); } fails to compile with usr/local/src/dmd2/src/phobos/std/conv.d(295): Error: function object.Object.toString () is not callable using argument types () whereas if I just take all the shared away it compiles fine. I imagine that this is somewhere to do with a string function being called on an element of the array and then there's no shared version of that method. Is there a fix? Or a different way to call sort? I can cast away shared for the sort but since in the actual application I have a reason for it, that's a bit worrisome. Thanks!This should be fixed in svn. I encountered a very similar issue, and implemented a fix. This will be fixed in the next release: http://d.puremagic.com/issues/show_bug.cgi?id=4901 -Steve
Jan 21 2011
Thanks! I tried to apply that patch and rebuild phobos (I changed the file, remade libphobos2.a, put it in /usr/local/lib). That worked but I still get my error. I might have done the applying or rebuilding wrong though, especially since once I did that, even with the casting away of shared, I get some linker errors. I'll wait for the next release, I guess, and in the meantime cast away "shared" and be very afraid. Is there any way to fix it otherwise by making the elts printable? Adam
Jan 21 2011
On Fri, 21 Jan 2011 10:04:56 -0500, Adam Conner-Sax <adam_conner_sax yahoo.com> wrote:Thanks! I tried to apply that patch and rebuild phobos (I changed the file, remade libphobos2.a, put it in /usr/local/lib). That worked but I still get my error. I might have done the applying or rebuilding wrong though, especially since once I did that, even with the casting away of shared, I get some linker errors. I'll wait for the next release, I guess, and in the meantime cast away "shared" and be very afraid. Is there any way to fix it otherwise by making the elts printable?Hm... it's a simple patch. Maybe there is something different I'm not seeing. I'll see if I can reproduce with my build. -Steve
Jan 21 2011
On Fri, 21 Jan 2011 10:09:18 -0500, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Fri, 21 Jan 2011 10:04:56 -0500, Adam Conner-Sax <adam_conner_sax yahoo.com> wrote:Compiled your code and ran it without error (well, got a segfault because the elements are all null), so I think maybe the patch wasn't applied properly on your machine. I guess all I can recommend is either to get phobos from svn or wait for the next release. -SteveThanks! I tried to apply that patch and rebuild phobos (I changed the file, remade libphobos2.a, put it in /usr/local/lib). That worked but I still get my error. I might have done the applying or rebuilding wrong though, especially since once I did that, even with the casting away of shared, I get some linker errors. I'll wait for the next release, I guess, and in the meantime cast away "shared" and be very afraid. Is there any way to fix it otherwise by making the elts printable?Hm... it's a simple patch. Maybe there is something different I'm not seeing. I'll see if I can reproduce with my build.
Jan 21 2011
Thanks. I'll wait for now since (gulp!) casting away shared just for the sort works and I'm not sure what I'm doing wrong with the patching. Adam
Jan 23 2011