problem with template arguments deduction

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jun 1 02:59:26 PDT 2012


On Friday, 1 June 2012 at 08:08:19 UTC, Zhenya wrote:
> Вот у нас есть такая конструкция
> template foo(T)
> {
>         foo(U)()
>         {
>         }
> }
> Могут ли у компилятора при
> инстанциировании возникнуть
> трудности с пониманием
> какие аргументы к какому шаблону
> относятся?
> Вопрос у меня возник из-за того,что
> когда я применил совет Philippe Sigaud
> к своему полному коду компилятор 
> не
> захотел его компилировать.Но когда
> я поменял имя внутреннего шаблона
> все стало хорошо.Это ведь
> неправильно?

In other words:

Given this construct:
> template foo(T)
> {
>         foo(U)()
>         {
>         }
> }
Could there be some problems with compiler not understanding 
which template argument goes to which template here? The question 
was born when I started applying Philippe Siguad's advice to my 
full source code compiler rejected it.
But when I change inner tmeplate name it worked - it's no good, 
is it?

Вопрос довольно сложный. Краткий 
ответ - нет, все идет слева направо, 
сверху вниз.
Есть впрочем одно но - компилятор 
начинает выводить типы из 
аргументов только для последнего foo 
(т.е. U). То есть T в это случае дается 
сверху (тобой через foo!T(...) ).
Впрочем в твоем примере foo не моежт 
вывести U из аргументов (их нет).

Difficult Q. In short - no, it's all left-to-right up-to-bottom.
However compiler may deduce types only for lowest foo (i.e. U). T 
in this case have to provided from above (by you as in 
foo!T(...)).


---
It's me, just trying out web interface.



More information about the Digitalmars-d-learn mailing list