Bug 6614 – std.traits should have an isFinal template

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-09-06T16:22:00Z
Last change time
2013-01-26T20:32:50Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-09-06T16:22:20Z
std.traits should have an isFinal template which indicates if a class type or member function is final. class A{} final class B{} static assert(!isFinal!A && isFinal!B); class C{int foo();} class D{final int foo();} static assert(!isFinal!(C.foo) && isFinal!(D.foo));
Comment #1 by andrej.mitrovich — 2012-12-02T09:56:01Z
We do have a trait for this: class A{} final class B{} void main() { static assert(!__traits(isFinalClass, A)); static assert(__traits(isFinalClass, B)); } Not too sure if it's worth having it as a template in std.traits?
Comment #2 by andrej.mitrovich — 2012-12-02T09:57:00Z
For functions there's: __traits(isFinalFunction, ...)
Comment #3 by andrej.mitrovich — 2012-12-27T12:59:59Z
So is the idea of the enhancement just to merge the two traits under a single name via Phobos templates? E.g. (using overloads): import std.traits; template isFinal(T) if (is(T == class)) { enum bool isFinal = __traits(isFinalClass, T); } template isFinal(alias T) if (isSomeFunction!T) { enum bool isFinal = __traits(isFinalFunction, T); } class C { void nf() { } static void sf() { } final void ff() { } } final class FC { } static assert(!isFinal!(C.nf)); static assert(!isFinal!(C.sf)); static assert(isFinal!(C.ff)); static assert(!isFinal!(C)); static assert(isFinal!(FC));
Comment #4 by andrej.mitrovich — 2013-01-22T15:11:14Z
Ping! :]
Comment #5 by timon.gehr — 2013-01-23T01:17:10Z
(In reply to comment #4) > Ping! :] Yes, looks good.
Comment #6 by andrej.mitrovich — 2013-01-25T15:00:11Z
Comment #7 by github-bugzilla — 2013-01-26T20:32:40Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/40cca46b4289dab8a072fa6ed9188347b2579db4 Fixes Issue 6614 - Add isFinalFunction and isFinalClass. Add isAbstractClass to mirror __traits().