template parameters
Christopher Wright
dhasenan at gmail.com
Fri Sep 25 15:45:47 PDT 2009
Ellery Newcomer wrote:
> Okay, let me rephrase that:
>
> When you have a <something> preceded by a colon in a template value
> parameter, what are its semantics? Is it the same as a default parameter
> value? Is it some sort of constraining expression? Is it a vestige?
void foo(T : int)(T value)
{
// value is implicitly convertible to int
}
It can do some pattern matching:
void foo(T : V[U], V, U)(T dictionary)
{
// I have an associative array
}
In D2, it's usually going to be easier to use constraints:
template foo(T) if (isAssociativeArray!T) {}
More information about the Digitalmars-d-learn
mailing list