Bug 8762 – instanceOf trait for static conditionals
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-05T02:23:00Z
Last change time
2015-06-09T05:15:23Z
Assigned to
nobody
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2012-10-05T02:23:10Z
As discussed here:
http://forum.dlang.org/thread/[email protected]
The idea would be a trait "instanceOf!T" that returns a reference to a T. The advantage of this approach is that it allows "extracting" an instance out of T, without ever worrying about how or where said instance came from.
This is particularly important because some types don't have T.init, and immutables don't have T t = void. The intersection of both these groups is {0} ...
Example:
//----
template isAssignable(T, U)
{
enum bool isAssignable =
is(typeof(instanceOf!T = instanceOf!U));
}
//----
The "signature" (as improved on by Simen Kjaeraas) would be:
//----
@property ref T instanceOf( T )( );
//----
But remain un-implemented.
This would ensure it is not actually usable during run-time.
Comment #2 by andrej.mitrovich — 2014-04-24T18:46:41Z
We have lvalueOf/rvalueOf now, is this sufficient?
Comment #3 by monarchdodra — 2014-04-24T20:09:06Z
(In reply to Andrej Mitrovic from comment #2)
> We have lvalueOf/rvalueOf now, is this sufficient?
Yes. Wow, I posted this a long time ago...
Closing as fixed.