opConcatAll?
Steven Schveighoffer
schveiguy at gmail.com
Thu Jul 2 20:29:59 UTC 2020
On 7/2/20 3:18 PM, jmh530 wrote:
> On Thursday, 2 July 2020 at 18:40:21 UTC, Steven Schveighoffer wrote:
>>> [snip]
>>>
>>> With a few small changes, you could just as easily have written
>>>
>>> int[] newArr;
>>> newArr[] = [0, 0, 0] + arr[] + [4, 5, 6];
>>>
>>> which is similar to the traditional type of problem that expression
>>> templates were designed to solve.
>>
>> Hm.. I think you misunderstand the example.
>>
>
> I think I understand the example, but I may not have made my point clear
> enough...
>
> You are concerned about a ~ b ~ c and avoiding unnecessary allocations.
>
> Expression templates are concerned with problems like a + b + c and
> avoiding the use of unnecessary temporaries.
>
> They seem like similar problems to me. Temporaries and allocations are
> obviously different, but the structure of the problem is similar. You
> yourself note that "most of the allocations as temporaries".
>
> If my point makes sense, then the implication is that this is a problem
> that is not unique to concatenation and also applies to the mathematical
> operators, in their own way.
OK, I see what you are saying. And yes, a generalized mechanism to
handle this would be useful for both avoiding allocations and avoiding
temporaries (among other things).
Nick's idea is pretty good for both.
-Steve
More information about the Digitalmars-d
mailing list