defaulting leading template parameters?
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Wed Nov 1 04:27:11 PST 2006
Sean Kelly wrote:
> d-bugmail at puremagic.com wrote:
>>
>> void testfunc(DUMMY = void, T)(int x, T a) {
>> writefln("x = %d, a = %s", x, a);
>> }
>
> I had no idea this was legal--it isn't in C++. I guess the rationale is
> that if the compiler can figure out the remaining parameters by
> inspecting function arguments then this is not an error?
>
>
> Sean
Well, I've never actually learned C++ templates[*], so I my thinking
isn't bound to what C++ can or cannot do :P . Anyway, I'm not sure I
understand your question. At the time I just checked the docs to see
what could be done with IFTI, and it was stated that:
"Template arguments not implicitly deduced can have default values:
void Foo(T, U=T*)(T t) { U p; ... }
"
So in both explicit and implicit instantiation you can also have
parameters that are deduced from other parameters. (Not the case in C++
then?) The DUMMY case above is just a case where such deduction is
constant and not actually dependent on any other parameters.
[*] Well, I did a learn some of C++ templates, but only the basics, and
only after learning D's and also usually under the perspective of D
comparison.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-bugs
mailing list