Thread overview | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 08, 2013 UFCS for templates | ||||
---|---|---|---|---|
| ||||
Can we have UFCS for templates? e.g., T New(T, A...)(A args) { } T t = T.New(args); Note, in this case, the type parameter is substituted. |
August 08, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
> Can we have UFCS for templates?
>
> e.g.,
>
> T New(T, A...)(A args) { }
>
>
> T t = T.New(args);
>
>
> Note, in this case, the type parameter is substituted.
That would be nice things to have, it would allow the parse!type(...) to be turned into type.parse(...) which is the C# way of doing it
Im just not sure if there would ever be a time where this might cause ambiguity, like where it was not obvious if the thing before the '.' should be the first type in the template or the first argument in the function.
|
August 08, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
> Can we have UFCS for templates?
>
> e.g.,
>
> T New(T, A...)(A args) { }
>
>
> T t = T.New(args);
>
>
> Note, in this case, the type parameter is substituted.
As always, providing motivating use case and advantage/cost comparison is usual requirement to make something happen.
DIP's exist for a reason.
|
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Thursday, 8 August 2013 at 17:55:04 UTC, Dicebot wrote:
> On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
>> Can we have UFCS for templates?
>>
>> e.g.,
>>
>> T New(T, A...)(A args) { }
>>
>>
>> T t = T.New(args);
>>
>>
>> Note, in this case, the type parameter is substituted.
>
> As always, providing motivating use case and advantage/cost comparison is usual requirement to make something happen.
>
> DIP's exist for a reason.
Are you not smart enough to come up with use cases yourself? This is not some extremely rare thing that might be used 1 in 10^100.
|
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Friday, 9 August 2013 at 00:34:31 UTC, JS wrote:
> Are you not smart enough to come up with use cases yourself? This is not some extremely rare thing that might be used 1 in 10^100.
It's not his proposal. The burden of proof is on you.
|
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Friday, 9 August 2013 at 00:57:21 UTC, Mike Parker wrote:
> On Friday, 9 August 2013 at 00:34:31 UTC, JS wrote:
>
>> Are you not smart enough to come up with use cases yourself? This is not some extremely rare thing that might be used 1 in 10^100.
>
> It's not his proposal. The burden of proof is on you.
Um, not really... Do you think that god made some law that requires me to? If he, you, or anyone else doesn't think such a feature is a good idea then so be it... It' not my problem is you want the D language to suffer. At some point something better will come with better features and D will succumb and all the time you invested will be a waste.
I would think that if you really cared about the D lang you would want it to be the best it can...
In any case, I know very well that it is quite useless for me to make suggestions for D... but I'm definitely not going to sit here and type up use cases because you are too lazy, don't have the foresight, or don't care to think about the issue. The fact is, I'm most likely not going to be able to convince you to accept anything I say because:
1. Something only useful to you is acceptable. You don't find this useful because you haven't used this construct, hence it is not acceptable. (This is generally known as close minded)
2. Generally things I "propose" are simplifications of semantics. I like to work efficiently. My proposes can be accomplished long hand... and for you, that is good enough... Either because you do not use such semantics and hence get tired of the inefficiency or don't like simplifications because you inanely feel they take away from the language by adding too much "overhead"(in some form or another).
So it is what it is. Take it or leave it. I've given the proposal, in maybe 10 years D will probably get around to having it... if it's still around at all.
|
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | So instead of: T t = New!T(args) you would like: T t = T.New(args) Is that it? |
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to barryharris | On Friday, 9 August 2013 at 03:41:56 UTC, barryharris wrote: > So instead of: > > T t = New!T(args) > > you would like: > > T t = T.New(args) > > Is that it? Never mind, I read your original post again... >> Note, in this case, the type parameter is substituted. |
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Thursday, 8 August 2013 at 17:35:02 UTC, JS wrote:
> Can we have UFCS for templates?
>
> e.g.,
>
> T New(T, A...)(A args) { }
>
>
> T t = T.New(args);
>
>
> Note, in this case, the type parameter is substituted.
Actually, what is wrong with New!T(args)? This works fine for me:
T t = New!T(args) ??
template New(T) if(is(T == class)) {
T New(A...)(A args) {
return new T(args);
}
}
class Test {
this(in string s, in int i) {
writefln("s=%s, i=%s", s, i);
}
}
class AnotherTest {
this(in int i) {
writefln("i=%s", i);
}
}
void main() {
auto test = New!Test("test", 10);
auto test2 = New!AnotherTest("test2", 20);
}
|
August 09, 2013 Re: UFCS for templates | ||||
---|---|---|---|---|
| ||||
Posted in reply to barryharris | >
> auto test2 = New!AnotherTest("test2", 20);
oops, should read:
auto test2 = New!AnotherTest(20);
--------------------
-1 for me anyway for the following reason:
A.function(args) // I know A is a function value parameter
function!A(args) // I know A is a template type parameter
function!10(args) // I know 10 is a template type parameter
10.function(args) // I know 10 is a function value parameter
So I don't like it...
|
Copyright © 1999-2021 by the D Language Foundation