Have a look at the sourcecode [1].
It is just implemented with an associative array (implemented as hash table) from argument tuples to the return type.
This means that keys have to be atomic or provide their to_hash and equality check themselves.
Check out the D template system, it is quite impressive what you can express with it.
1: https://github.com/D-Programming-Language/phobos/blob/master...