Trying to sort shared data with a predicate causes 'unable to format shared objects'

George Sapkin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 16 19:45:28 PDT 2014


I'm trying to sort shared data with a predicate. Buy that causes 
'unable to format shared objects'. Here's an example reproducing 
the issue without any threading code:

shared class SomeClass {
    immutable int value;

    this(const int value) {
       this.value = value;
    }
}

void main() {
     auto n = 10;
     auto data = new shared SomeClass[n];

     foreach (i; 0..n) data[i] = new shared SomeClass(i);
     auto sorted = sort!((a, b) => a.value < b.value)(data);
}

Causes:

/usr/include/dmd/phobos/std/format.d(2616): Error: static assert  
"unable to format shared objects"
/usr/include/dmd/phobos/std/conv.d(108):        instantiated from 
here: formatValue!(Appender!string, shared(SomeClass), char)
/usr/include/dmd/phobos/std/conv.d(879):        instantiated from 
here: toStr!(string, shared(SomeClass))
/usr/include/dmd/phobos/std/conv.d(282):        instantiated from 
here: toImpl!(string, shared(SomeClass))
/usr/include/dmd/phobos/std/conv.d(3332):        instantiated 
from here: to!(shared(SomeClass))
/usr/include/dmd/phobos/std/conv.d(3316):        instantiated 
from here: textImpl!(string, string, shared(SomeClass), string, 
shared(SomeClass), string, ulong, string, ulong)
/usr/include/dmd/phobos/std/algorithm.d(10352):        
instantiated from here: text!(string, shared(SomeClass), string, 
shared(SomeClass), string, ulong, string, ulong)
/usr/include/dmd/phobos/std/algorithm.d(9068):        
instantiated from here: isSorted!(__lambda1, shared(SomeClass)[])
sort.d(16):        instantiated from here: sort!((a, b) => 
a.value < b.value, cast(SwapStrategy)0, shared(SomeClass)[])

I'm using DMD64 2.065 on Fedora 20.

Any ideas what I'm doing wrong? Thanks.


More information about the Digitalmars-d-learn mailing list