Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add isFinalFunction, isAbstractClass, and isFinalClass to std.traits #1099

Merged
merged 2 commits into from

1 participant

@ghost

http://d.puremagic.com/issues/show_bug.cgi?id=6614

As per Walter's comment __traits should have template equivalents.

Andrej Mitrovic added some commits
Andrej Mitrovic Improve isAbstractFunction and add unittest. e387b6f
Andrej Mitrovic Fixes Issue 6614 - Add isFinalFunction and isFinalClass.
Add isAbstractClass to mirror __traits().
40cca46
@alexrp alexrp commented on the diff
std/traits.d
((7 lines not shown))
*/
-template isAbstractFunction(method...)
- if (method.length == 1)
+template isAbstractFunction(T...)
@alexrp Collaborator
alexrp added a note

Why are the varargs necessary?

@ghost
ghost added a note

It seems to be a convention in Phobos to allow both types and non-types to pass through. alias iteslf doesn't accept types.

@alexrp Collaborator
alexrp added a note

OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@alexrp
Collaborator

LGTM other than my question.

@alexrp alexrp merged commit 74d8804 into from
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 25, 2013
  1. Improve isAbstractFunction and add unittest.

    Andrej Mitrovic authored
  2. Fixes Issue 6614 - Add isFinalFunction and isFinalClass.

    Andrej Mitrovic authored
    Add isAbstractClass to mirror __traits().
This page is out of date. Refresh to see the latest.
Showing with 76 additions and 5 deletions.
  1. +76 −5 std/traits.d
View
81 std/traits.d
@@ -5103,16 +5103,87 @@ unittest
/**
-Exactly the same as the builtin traits:
-$(D ___traits(_isAbstractFunction, method)).
+ * Detect whether $(D T) is a an abstract function.
*/
-template isAbstractFunction(method...)
- if (method.length == 1)
+template isAbstractFunction(T...)
@alexrp Collaborator
alexrp added a note

Why are the varargs necessary?

@ghost
ghost added a note

It seems to be a convention in Phobos to allow both types and non-types to pass through. alias iteslf doesn't accept types.

@alexrp Collaborator
alexrp added a note

OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (T.length == 1)
+{
+ enum bool isAbstractFunction = __traits(isAbstractFunction, T[0]);
+}
+
+unittest
{
- enum bool isAbstractFunction = __traits(isAbstractFunction, method[0]);
+ struct S { void foo() { } }
+ class C { void foo() { } }
+ class AC { abstract void foo(); }
+ static assert(!isAbstractFunction!(S.foo));
+ static assert(!isAbstractFunction!(C.foo));
+ 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
Something went wrong with that request. Please try again.