Posted Thu, 29 Aug 2013 08:11:36 GMT in reply to
Jack Applegame
Reply
On Mon, 19 Aug 2013 23:04:57 GMT, Jack Applegame wrote:
Another issue is creating isolated objects of abstract types.
For example:
pure A makeA(T)(T data) { return new B!T(data); }
abstract class A {
void work();
}
class B(T) : A {
override void work() { data.work(); }
private this(T data) { _data = data; }
T _data;
}
It is impossible to create Isolated!A object because A is abstract.
We need something like
pure auto makeIsolatedFactory(F, ARGS...)(F factory, ARGS args) if(isCallable!F) {
return Isolated!(ReturnType!F)(factory(args));
}
or passing factory by template alias parameter (for templated factories)
Sorry, I had completely overlooked this message. However, I have implemented opCast now to provide a solution to the issue. So this should work:
abstract class A {
void work();
}
class B(T) : A {
override void work() { data.work(); }
private this(T data) { _data = data; }
T _data;
}
Isolated!B makeA(T)(T data)
{
return cast(Isolated!B)makeIsolated!A(data);
}
With some more compiler support it should also be possible to directly do this:
Isolated!B b = new A(data); // A.this() must be pure for this to work
Walter seemed to take a route that would allow this, but there as been no recent progress as far as I know.