Thread overview | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 28, 2015 The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/ |
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On 4/27/15 7:36 PM, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
s/which/that/
Simple rule of thumb: if there's no comma before "which", consider replacing with "that". -- Andrei
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 28 April 2015 at 06:10:28 UTC, Andrei Alexandrescu wrote:
> On 4/27/15 7:36 PM, Vladimir Panteleev wrote:
>> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
>
> s/which/that/
>
> Simple rule of thumb: if there's no comma before "which", consider replacing with "that". -- Andrei
Fixed, thanks.
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On Tuesday, 28 April 2015 at 02:36:38 UTC, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
Thanks for this little piece of information! Great stuff. You wrote
"When building an UFCS chain (in the style of component programming), you will often run into situations where a certain operation is not UFCS-able. There are multiple obvious ways to prepend the string, but neither are very satisfactory"
And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris | On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
A very slow (i guess) workaround could be:
"test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
vs the new one:
"test".toUpper.Identity!(a => "This is a " ~ a).writeln;
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>
> A very slow (i guess) workaround could be:
>
> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>
> vs the new one:
>
> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.
*Assuming a good optimiser. dmd won't work this out.
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Tuesday, 28 April 2015 at 10:18:12 UTC, John Colvin wrote:
> On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
>> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>>
>> A very slow (i guess) workaround could be:
>>
>> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>>
>> vs the new one:
>>
>> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
>
> Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.
>
> *Assuming a good optimiser. dmd won't work this out.
s/your/you're
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Tuesday, 28 April 2015 at 10:18:49 UTC, John Colvin wrote:
> On Tuesday, 28 April 2015 at 10:18:12 UTC, John Colvin wrote:
>> On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
>>> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>>>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>>>
>>> A very slow (i guess) workaround could be:
>>>
>>> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>>>
>>> vs the new one:
>>>
>>> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
>>
>> Shouldn't be slow, your just giving the optimiser some work to do*, but you're always better off with the second one.
>>
>> *Assuming a good optimiser. dmd won't work this out.
>
> s/your/you're
Trying on d.godbolt.com it seems a lot of extra-code is generated for the first version.
Anyway I think I'm going to rename it "apply". :)
"test".toUpper.apply!(a => "This is a " ~ a).writeln;
It sounds better.
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On Tuesday, 28 April 2015 at 02:36:38 UTC, Vladimir Panteleev wrote:
> http://blog.thecybershadow.net/2015/04/28/the-amazing-template-which-does-nothing/
Very nice. There is also a similar package protected template in std.typetuple, `Alias`. I used it a lot but last applicability case with UFCS chain didn't come to my mind. It looks very elegant.
I had plans to introduce it as a public helper in std.meta under the name `Symbol`, would that make sense?
|
April 28, 2015 Re: The amazing template which does nothing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Tuesday, 28 April 2015 at 10:07:43 UTC, Andrea Fontana wrote:
> On Tuesday, 28 April 2015 at 09:23:53 UTC, Chris wrote:
>> And this has happened to me many times. The solution "Break the UFCS chain and use a local temporary variable" makes me angry, because by having to do so all the beauty of chaining is lost.
>
> A very slow (i guess) workaround could be:
>
> "test".toUpper.only.map!(a => "This is a " ~ a).front.writeln;
>
> vs the new one:
>
> "test".toUpper.Identity!(a => "This is a " ~ a).writeln;
Using std.functional:
"test".toUpper.unaryFun!(a => "This is a " ~ a).writeln;
|
Copyright © 1999-2021 by the D Language Foundation