digitalmars.D.bugs - [Issue 8762] New: instanceOf trait for static conditionals
- d-bugmail puremagic.com (38/38) Oct 05 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8762
- d-bugmail puremagic.com (12/12) Oct 05 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8762
http://d.puremagic.com/issues/show_bug.cgi?id=8762 Summary: instanceOf trait for static conditionals Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: monarchdodra gmail.com --- Comment #0 from monarchdodra gmail.com 2012-10-05 02:23:10 PDT --- As discussed here: http://forum.dlang.org/thread/ssqgyxzggmzugbfbboay forum.dlang.org 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 05 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8762 --- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2012-10-05 22:06:12 PDT --- In std.traits module, similar utility already exists (but today, it is private template). And recently I've posted a pull request which updates it. https://github.com/D-Programming-Language/phobos/pull/842 https://github.com/D-Programming-Language/phobos/pull/842/files#L1R140 The name `defaultInit` comes from `default initializer` for T (, and the name is used in the dmd implementation). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 05 2012