Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no dedicated pattern-matching feature as powerful as in Haskell or Scala.</p> <p>As you have already figured out, overloading and calling (templated) functions or delegates is a restricted form of pattern matching. You can match on the argument types only.</p> <p>You can pattern match on <em>compile time</em> template arguments. It is not possible to extract an object's contents there either. But you can extract a type's contents.</p> <p>Eg :</p> <pre><code>import std.stdio, std.conv; template match(T...){ enum match = "default case"; } template match(string a : "x", int b : 1, int c){ enum match = "matched 1, b="~to!string(b); } template match(int a, string b, int c : 100){ enum match = "matched 2, b="~b; } template match(T : T[]*[]){ enum match = "matched 3, an array of pointers to an array of "~T.stringof; } void main(){ int a=100; writeln(match!("x",1,5)); // "matched 1, b=1" writeln(match!(12,"str")); // "default case" writeln(match!(12,"str",100)); // "matched 2, b=str" writeln(match!(int*[]*[])); // "matched 3, an array of pointers to an array of int*" //writeln(match!(12,"str",a)); // would be error, because 'a' // is not evaluable during compile time } </code></pre> <p>If you are interested, you may want to have a look at <a href="http://d-programming-language.org/template.html" rel="nofollow">http://d-programming-language.org/template.html</a> .</p> <p>'is' - Expressions are another way to pattern match on types, see</p> <p><a href="http://d-programming-language.org/expression.html" rel="nofollow">http://d-programming-language.org/expression.html</a> (search for "IsExpression").</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload