sort and shared

Steven Schveighoffer schveiguy at yahoo.com
Fri Jan 21 06:27:37 PST 2011


On Thu, 20 Jan 2011 21:14:06 -0500, Adam Conner-Sax  
<adam_conner_sax at 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


More information about the Digitalmars-d-learn mailing list