On 9/4/11 3:04 AM, Andrej Mitrovic wrote:
Ooh ok. But how is it different from just using a bang? An example
would be nice there.

Imagine you have a template predicate »hasType«, which checks if the passed expression has a type:

---
template hasType(T...) if (T.length == 1) {
  enum hasType = is(typeof(T[0]));
}
---

Now, you want to get the elements from a type tuple that don't have a type (e.g. types themselves, and this is one of the situations that show how confusing the name »type tuple« really is). But you can't just do »StaticFilter!(!hasType, Tuple)«, because you can't just »negate a template« like this.

In this situation, Not makes sense: »StaticFilter(Not!hasType, Tuple)«. If D supported something like template literals, Not wouldn't be needed, but as we don't have them, I know no other (easy) way of achieving the same.

By the way, Not could also be implemented as:
---
template not(T...) if (T.length == 1 && is(typeof(!T[0]) : bool)) {
  enum bool not = !T[0];
}
alias PApply!(Compose, not) Not;
---

I felt this would be somewhat over the top though… ;)

David

Reply via email to