Deducing types for function templates

Magnus Lie Hetland magnus at hetland.org
Tue Mar 15 07:42:46 PDT 2011


I've got a function template along these lines:

  Foo!T foo(T)(T[] bar, real function(T,T) baz) { ... }

The main reason I'm using this is that it seems necessary to use a 
function, rather than a type (such as Foo), if you want the compiler to 
deduce the compile-time parameters. (Right?)

Now ... this works just fine. However, if I try to add "const" before 
"T[]", DMD no longer groks it. Is that how it shold be? Seems awkward 
to me... (Or maybe I'm just doing it wrong?)

And a followup question: Writing out the type of baz like this (in 
several places) is also a bit awkward. I'd like to have a template so I 
could just do

  Foo!T foo(T)(T[] bar, baz_t!T baz) { ... }

However, I haven't been able to define such a template without running 
into the same problem (i.e., that DMD no longer can deduce what T 
should be from my arguments).

Any pointers?

-- 
Magnus Lie Hetland
http://hetland.org



More information about the Digitalmars-d-learn mailing list