for ( for-range-declaration : for-range-initializer ) statement{
auto &&__range = for-range-initializer ;
auto __begin = begin-expr ;
auto __end = end-expr ;
for ( ; __begin != __end; ++__begin ) {
for-range-declaration = *__begin;
statement
}
}{
auto &&__range = for-range-initializer ;
auto &&__range2 = for-range-initializer2 ;
auto __begin = begin-expr ;
auto __begin2 = begin-expr2;
auto __end = end-expr ;
auto __end2 = end-expr2 ;
for ( ; __begin != __end && __begin2 != __end2; ++__begin, ++__begin2 ) {
for-range-declaration = *__begin;
for-range-declaration2 = *__begin2;
statement
}
}
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhEBPCJYM4KoHx3hg8bfBmqEzX29%2BpWn6%3D1W3Sq2Sf0bZA%40mail.gmail.com.
template<int n> array<double, n> add(array<double, n>& x1, array<double, n>& x2) { array<double, n> sum; for (double& s : sum; double v1 : x1; double v2 : x2) { s = v1 + v2; } return sum;}template<int n> double dot(array<double, n>& x1, array<double, n> x2) { double sum = 0.0; for (double v1 : x1; double v2 : x2) { sum += v1 * v2; } return sum;}template<int rows, int cols> array<double, rows> mul(const array<array<double, cols>, rows>& matrix, const array<double, cols>& vector) { array<double, rows> result; for (const auto& row : matrix; double& sum : result) { sum = 0; for (double& x1 : row; double& x2 : vector) { sum += x1 * x2; } } return result;}for(auto &[x, y] : std::zip(rng1, rng2))for(auto &x : rng1 ; auto &y : rng2)E.g.
for (auto [a, b]: {list1, list2}) { ... }
Personally I don't like the idea of this. Feels dirty to me that we need to combine the different entities together just so we can iterate them at the same time. It almost seems like mixing concerns.
Also could a for loop as described in P0026 not be use to implement the zip method internals? It would be interesting to see how that is implemented compared with this proposal.
It was my understanding tha P0026 was refused due to another proposal allowing the mapping of parts within the initializer.E.g.
for (auto [a, b]: {list1, list2}) { ... }Personally I don't like the idea of this. Feels dirty to me that we need to combine the different entities together just so we can iterate them at the same time. It almost seems like mixing concerns.
Also could a for loop as described in P0026 not be use to implement the zip method internals?
On 8 August 2016 at 18:29, Nicol Bolas <jmck...@gmail.com> wrote:
> On Monday, August 8, 2016 at 1:14:05 AM UTC-4, Izzy Coding wrote:
>>
>> It was my understanding tha P0026 was refused due to another proposal
>> allowing the mapping of parts within the initializer.
>>
>> E.g.
>> for (auto [a, b]: {list1, list2}) { ... }
>>
>> Personally I don't like the idea of this. Feels dirty to me that we need
>> to combine the different entities together just so we can iterate them at
>> the same time. It almost seems like mixing concerns.
>
>
> But you are mixing concerns. You're iterating through multiple ranges
> simultaneously. The loop will end when one of the ranges ends. The behavior
> of the loop is based on the aggregation of the ranges.
>
> So actually aggregating them seems entirely appropriate.
Da huh? The code above looks like it creates an initializer_list of
list1 and list2, and
then tries to create a and b as decompositions of each element of that
initializer_list.
That certainly doesn't do what the multi-iteration range-for proposal
tried to do.
On segunda-feira, 8 de agosto de 2016 16:09:39 PDT Matthew Woehlke wrote:
> for(auto&& [x, y] : std::zip(long_list, std::pad(short_list, 0)))
>
> (...where std::pad is a hypothetical function that returns elements of
> the input list until it runs out, then returns the filler element forever.)
This is an infinite loop:
for (auto x : std::pad(short_list, 0))
On Monday, August 8, 2016 at 1:37:58 PM UTC-7, Thiago Macieira wrote:On segunda-feira, 8 de agosto de 2016 16:09:39 PDT Matthew Woehlke wrote:
> for(auto&& [x, y] : std::zip(long_list, std::pad(short_list, 0)))
>
> (...where std::pad is a hypothetical function that returns elements of
> the input list until it runs out, then returns the filler element forever.)
This is an infinite loop:
for (auto x : std::pad(short_list, 0))Note that the ranges proposal generalizes and clearly defines infinite ranges which are of course iterable in for-range. This isn't (won't be) a new problem.
My initial argument was that with a relatively simple change we could support looping multiple "ranges" directly in the language rather than making it a library feature. All the library options could still be usable and so this proposal would not affect anything. To me combining multiple ranges in a wrapper range still feels to me like mixing concerns.
E.G.
for (auto i = 0; i < min(range1.length, range2.length; ++i)
{
auto&& item1 = range1[i];
auto&& item2 = range2[i];
doSomethingWith(item1);
doSomethingRelatedButNotDirectlyConnectedWith(item2);
}
In this case other than doing 2 things in a single loop there is no direct connection between the two items. This would allow for multiple processes that maybe require a transaction. For example the usual financial example, an international account transaction maybe where range1 relates to amounts spent from a given account in one currency, range2 relates to the amount in another currency to pay into account 2. Account 1 and Account2 have nothing to do with each other than the transaction itself. I agree this is not the best way to design a system, but lots of us working on real code bases can't always change the legacy code that puts us in this position.
Personally I have always been available for comments and ideas on my proposal. Yes I had some personal things going on but I still have not had any interest at all thus far. Not even from the many people I have emailed it to. Not even a reply email to say "thanks but no thanks" or whatever.
As the author of the original proposal, other than the discussion referenced, I have had no interest from anyone to either champion or help do any other work to improve the proposal.
I read that my paper was read and considered, but was not adopted due to other work being done which would offer similar possibilities (I believe it was about the ranges v3).My initial argument was that with a relatively simple change we could support looping multiple "ranges" directly in the language rather than making it a library feature. All the library options could still be usable and so this proposal would not affect anything. To me combining multiple ranges in a wrapper range still feels to me like mixing concerns.
for (auto i = 0; i < min(range1.length, range2.length); ++i)
{
auto&& item1 = range1[i];
auto&& item2 = range2[i];
doSomethingWith(item1);
doSomethingRelatedButNotDirectlyConnectedWith(item2);
}
for (auto i = 0; i < max(range1.length, range2.length); ++i) ... // presumably pad the shorter range, whichever it is
for (auto i = 0; i < assert_equality(range1.length, range2.length); ++i) ...
or
for (auto i = 0; i < sum(range1.length, range2.length); ++i) ... // presumably concatenate the ranges
The particular way in which you aggregate the two ranges together is actually a very important parametrizable quantity. It's not clear why "min" ought to be privileged with a special language syntax but "max" not be.
But if we let the aggregation function be a parameter, and then we notice that assert_equality corresponds basically to zip() and sum corresponds basically to concat() and we start filling in missing primitives... well, before long, we've invented Ranges V3. ;)
So the natural inclination of Committee-folks is probably something like "Ranges exists and/or is coming; core language changes are hard; this core language change is both incomplete/asymmetric *and* redundant with Ranges; so, no." If you think the proposal is good (which, again, I don't, so I think you should drop it), then you're going to have to figure out a way to change folks' minds.
I agree this is not the best way to design a system, but lots of us working on real code bases can't always change the legacy code that puts us in this position.
Personally I have always been available for comments and ideas on my proposal. Yes I had some personal things going on but I still have not had any interest at all thus far. Not even from the many people I have emailed it to. Not even a reply email to say "thanks but no thanks" or whatever.
--
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/TqfLLDb6DW0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposal...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2d388706-0c16-4dd6-a3bf-57798da3d5ca%40isocpp.org.