| Thread overview | |||||
|---|---|---|---|---|---|
|
December 15, 2007 Changing the template defintion syntax. | ||||
|---|---|---|---|---|
| ||||
One thing that has bugged me for a while is the in symmetry of how template are defined and used. If template were defined with !() instead of () it would also allow multi-level template to be defined with out the "same name as template" kludge. For example U to!(U)!(T)(T t); And while on the note of to, it would be nice if cast used template syntax (as well as any keyword function that took or returned types (const, invariant, typeof, typeid, etc.)). Also the template keyword could be replace with a generic namespace keyword. We could even let all definitions be templatable T template_variable!(T); I don't know how practicable or use full that would be though. | ||||
December 18, 2007 Re: Changing the template defintion syntax. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Robert DaSilva | On Sat, 15 Dec 2007, Robert DaSilva wrote: > One thing that has bugged me for a while is the in symmetry of how > template are defined and used. If template were defined with !() instead > of () it would also allow multi-level template to be defined with out > the "same name as template" kludge. > For example > U to!(U)!(T)(T t); I think you're confusing a lot of things here. Changing the syntax isn't enough to make the static parameters of a functions partially applicable. Also I'm not sure if a change in the syntax is needed. You could achieve the same thing with implicit currying. Another thing is that what you're showing here isn't the only thing that can be done with nested templates. The C++ style "anonymous" parametrization is cleaner in this case, but in D you can also change the declaration type inside the template: template foo(int i) { static if(i == 0) class foo {} else int foo; } > And while on the note of to, it would be nice if cast used template > syntax (as well as any keyword function that took or returned types > (const, invariant, typeof, typeid, etc.)). Why? > > Also the template keyword could be replace with a generic namespace keyword. What? Templates form a namespace, but that doesn't mean templates are equivalent to namespaces. What would be useful though is to be able to instantiate templates with no parameters or templates with only parameters with default values without using !() syntax. But then, how would one differentiate between template symbol and instantiation. > > We could even let all definitions be templatable > T template_variable!(T); > I don't know how practicable or use full that would be though. Huh? | |||
December 18, 2007 Re: Changing the template defintion syntax. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jari-Matti Mäkelä | Jari-Matti Mäkelä wrote: > On Sat, 15 Dec 2007, Robert DaSilva wrote: > >> One thing that has bugged me for a while is the in symmetry of how >> template are defined and used. If template were defined with !() instead >> of () it would also allow multi-level template to be defined with out >> the "same name as template" kludge. >> For example >> U to!(U)!(T)(T t); > > I think you're confusing a lot of things here. Changing the syntax isn't enough to make the static parameters of a functions partially applicable. Also I'm not sure if a change in the syntax is needed. You could achieve the same thing with implicit currying. The main reason for the suggestion is the symmetry, I'm just adding thinks that would possible with the syntax change. > > Another thing is that what you're showing here isn't the only thing that can be done with nested templates. The C++ style "anonymous" parametrization is cleaner in this case, but in D you can also change the declaration type inside the template: > > template foo(int i) { > static if(i == 0) > class foo {} > else > int foo; > } > > >> And while on the note of to, it would be nice if cast used template >> syntax (as well as any keyword function that took or returned types >> (const, invariant, typeof, typeid, etc.)). > > Why? Consistency. > >> >> Also the template keyword could be replace with a generic namespace keyword. > > What? Templates form a namespace, but that doesn't mean templates are equivalent to namespaces. What would be useful though is to be able to instantiate templates with no parameters or templates with only parameters with default values without using !() syntax. But then, how would one differentiate between template symbol and instantiation. I never said they were the same thing. But a templated namespace is equivalent to the current template implementation. > >> >> We could even let all definitions be templatable >> T template_variable!(T); >> I don't know how practicable or use full that would be though. > > Huh? It would be the same as template template_variable(T) { T template_variable; } | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply