On Saturday, 13 August 2016 at 12:47:40 UTC, Ethan Watson wrote:

                             |  Rust   |  Swift  |    C#   |
-----------------------------|---------+---------+---------|
    Template Constraints     |    Y    |    Y    |  where  | [1]
-----------------------------|---------+---------+---------|
  Template "if" Constraints  |  where  |  where  |  where  |
-----------------------------|---------+---------+---------|
        static if            |    N    |    N    |    N    |
-----------------------------|---------+---------+---------|

It might be something to note that C# doesn't have templates. Generics can only have type parameters (i.e. `int` or `string` not `5` or `Hello World`), and the `where` constraint is pretty restricted in what it can do: o Is T or is subclass of T/implements interface (class C<T> where T : U)
o Default/parameterless constructor (class C<T> where T : new())
o Reference/value type checking (class C<T> where T : class/where T : struct)

For "static if," C# also has a very limited conditional compilation system that is barely comparable. Symbols can be defined at compile time, but they can't have values and they can only be used with specific directives:
---
#define X

#if X
    doA();
#else
    doB();
#endif
---

Reply via email to