Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Issue 6614 - Add isFinalFunction and isFinalClass.

Add isAbstractClass to mirror __traits().
  • Loading branch information...
commit 40cca46b4289dab8a072fa6ed9188347b2579db4 1 parent e387b6f
Andrej Mitrovic authored
Showing with 63 additions and 0 deletions.
  1. +63 −0 std/traits.d
View
63 std/traits.d
@@ -5121,6 +5121,69 @@ unittest
static assert(isAbstractFunction!(AC.foo));
}
+/**
+ * Detect whether $(D T) is a a final function.
+ */
+template isFinalFunction(T...)
+ if (T.length == 1)
+{
+ enum bool isFinalFunction = __traits(isFinalFunction, T[0]);
+}
+
+unittest
+{
+ struct S { void bar() { } }
+ final class FC { void foo(); }
+ class C
+ {
+ void bar() { }
+ final void foo();
+ }
+ static assert(!isFinalFunction!(S.bar));
+ static assert(isFinalFunction!(FC.foo));
+ static assert(!isFinalFunction!(C.bar));
+ static assert(isFinalFunction!(C.foo));
+}
+
+/**
+ * Detect whether $(D T) is a an abstract class.
+ */
+template isAbstractClass(T...)
+ if (T.length == 1)
+{
+ enum bool isAbstractClass = __traits(isAbstractClass, T[0]);
+}
+
+unittest
+{
+ struct S { }
+ class C { }
+ abstract class AC { }
+ static assert(!isAbstractClass!S);
+ static assert(!isAbstractClass!C);
+ static assert(isAbstractClass!AC);
+}
+
+/**
+ * Detect whether $(D T) is a a final class.
+ */
+template isFinalClass(T...)
+ if (T.length == 1)
+{
+ enum bool isFinalClass = __traits(isFinalClass, T[0]);
+}
+
+unittest
+{
+ class C { }
+ abstract class AC { }
+ final class FC1 : C { }
+ final class FC2 { }
+ static assert(!isFinalClass!C);
+ static assert(!isFinalClass!AC);
+ static assert(isFinalClass!FC1);
+ static assert(isFinalClass!FC2);
+}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
// General Types
Please sign in to comment.
Something went wrong with that request. Please try again.