1

Topic: C ++ idea for the standard.

There are 3 containers: a, b, c. I want to launch 1 range-cycle on them all simultaneously: for (auto i1: a, auto i2: b, auto i3: c) {} On each iteration i1, i2, i3 has the next value from the appropriate container. The cycle dies as soon as the smallest container will be settled. An example: std:: vector <int> a = {1, 2, 3}; std:: vector <std:: string> b = {"hello", "world", "foo", "bar"}; std:: vector <int> c = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};//Loop will stop after 3 iterations, because ' a ' have minumal size = 3. for (auto i1: a, auto i2: b, auto i3: c) {std:: cout <<i1 <<"," <<i2 <<"," <<i3 <<"\n";} Output: 1, hello, 9 2, world, 8 3, foo, whether 7 Ass it? I the stupid addict? Whether it is possible to make it already  without ?

2

Re: C ++ idea for the standard.

Hello, pkl, you wrote: whether pkl> the Ass it? I the stupid addict? Whether it is possible to make it already  without ? You can offer them it personally. Improvings so-so if fairly and me it seems it is possible  inventing a class-wrapper of containers-containers.

3

Re: C ++ idea for the standard.

Hello, pkl, you wrote: whether pkl> It is possible to make it already  without ? It is possible. Something turns out like zip_iterator

4

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> There are 3 containers: a, b, c. I want to launch 1 range-cycle on them all simultaneously: it would be logical to make as three nested loops for (auto i1: a, auto i2: b, auto i3: c) {} tearing in for (auto i1: a) {for (auto i2: b) {for (auto i3: c) {}}}

5

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> On each iteration i1, i2, i3 has the next value from the appropriate container. pkl> the cycle dies as soon as the smallest container will be settled. Such run normally becomes through zip. On pluses it is verbose it is possible to make in  a word zip it is possible to meet in  and a python to expand syntax of a C ++ for zip it seems , is better something such to have in stl

6

Re: C ++ idea for the standard.

Hello, night beast, you wrote: NB> Hello, pkl, you wrote: whether pkl>> It is possible to make it already  without ? NB> it is possible. Something turns out like zip_iterator It a little more . It would be desirable in 1 line the built in means, without adding the .

7

Re: C ++ idea for the standard.

Hello, GhostCoders, you wrote: GC> Hello, pkl, you wrote: pkl>> There are 3 containers: a, b, c. I want to launch 1 range-cycle on them all simultaneously: GC> it would be logical to make as three nested loops GC> GC> for (auto i1: a, auto i2: b, auto i3: c) {GC>} GC> GC> tearing in GC> GC> for (auto i1: a) {GC> for (auto i2: b) {GC> for (auto i3: c) {GC>} GC>} GC>} GC> it is not logical. At enclosed another .

8

Re: C ++ idea for the standard.

Hello, pkl, you wrote: GC>> for (auto i1: a, auto i2: b, auto i3: c) {pkl> it is not logical. At enclosed another . I Mean that for syntax above it is more logical to use nested semantics, instead of zip.

9

Re: C ++ idea for the standard.

Hello, GhostCoders, you wrote: GC> Hello, pkl, you wrote: GC>>> for (auto i1: a, auto i2: b, auto i3: c) {pkl>> it is not logical. At enclosed another . GC> I Mean that for syntax above it is more logical to use nested semantics, instead of zip. Did not understand why more logically. You at first run on internal, then take a step on exterior and anew run on the internal.

10

Re: C ++ idea for the standard.

Whether pkl> the Ass it? I the stupid addict? Whether it is possible to make it already  without ? And three iterators and usage normal while a cycle and three checks on end () any more a C ++? It is necessary to change the standard?

11

Re: C ++ idea for the standard.

Hello, rean, you wrote: R> And three iterators and usage normal while a cycle and three checks on end () any more a C ++? It is necessary to change the standard?... Or 1 index.

12

Re: C ++ idea for the standard.

Hello, rean, you wrote: whether pkl>> the Ass it? I the stupid addict? Whether it is possible to make it already  without ? R> And three iterators and usage normal while a cycle and three checks on end () any more a C ++? It is necessary to change the standard? Well changed the standard, entering range based loops though it was possible to manage iterators.

13

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> did not understand why more logically. Because it is the very first association when you see such code. Similar on list comprehension: https://en.wikipedia.org/wiki/List_comprehension

14

Re: C ++ idea for the standard.

Hello, pkl, you wrote: whether pkl> the Ass it? I the stupid addict? Whether it is possible to make it already  without ? https://stdcpp.ru/proposals

15

Re: C ++ idea for the standard.

Hello, uzhas, you wrote: U> Hello, pkl, you wrote: pkl>> did not understand why more logically. U> because it is the very first association when you see such code. Similar on list comprehension: https://en.wikipedia.org/wiki/List_comprehension the code works For the dude not so: he many times runs on 3, less time runs on 2 and once runs on 1. It at all that did my code of the first post.

16

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> the code works For the dude not so give you you will narrow eyes, you will make a deep breath and an exhalation, and then you will re-read a branch and you will try to understand, what to you write ?

17

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> There are 3 containers: a, b, c. I want to launch 1 range-cycle on them all simultaneously: pkl> pkl> for (auto i1: a, auto i2: b, auto i3: c) {pkl>} pkl> And why not somehow so: for (auto i1, i2, i3: std:: tie (a, b, c))

18

Re: C ++ idea for the standard.

Hello, Nik, you wrote: N> And why not somehow so: N> for (auto i1, i2, i3: std:: tie (a, b, c)) it is easy to confuse with structured binding from a C ++ 17: auto [i1, i2, i3] = std:: tie (a, b, c);?

19

Re: C ++ idea for the standard.

Hello, rean, you wrote: whether pkl>> the Ass it? I the stupid addict? Whether it is possible to make it already  without ? R> And three iterators and usage normal while a cycle and three checks on end () any more a C ++? It is necessary to change the standard? Looked, how much difficult it turns out. It turns out not difficult and quite readably: std:: vector <int> a = {1, 2, 3}; std:: vector <std:: string> b = {"hello", "world", "foo", "bar"}; std:: vector <int> c = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; auto ia = a.begin (); auto ib = b.begin (); auto ic = c.begin (); for (; wink {bool in_a = ia! = a.end (); bool in_b = ib! = b.end (); bool in_c = ic! = c.end (); if (! (in_a || in_b || in_c)) break; if (in_a) std:: cout <<*ia; else std:: cout <<"-"; if (in_b) std:: cout <<"," <<(*ib).c_str (); else std:: cout <<", -"; if (in_c) std:: cout <<"," <<*ic; else : cout <<std:: endl; if (in_a) ++ ia; if (in_b) ++ ib; if (in_c) ++ ic;}; the Output: 1, hello, 9 2, world, 8 3, foo, 7 - bar, 6 - - 5 - - 4 - - 3 - - 2 - - 1 - - 0 Most part of complexities because of std:: cout, whether and to check where you are in vectors and ended to check unexpectedly in any place, all the same it is necessary. Any syntactic sugar to make it does not turn out. Only all complicates.

20

Re: C ++ idea for the standard.

Hello, rean, you wrote: R> Looked, how much difficult it turns out. It turns out not difficult and quite readably: at you , but it is unimportant, since works incorrectly here so it is necessary: https://ideone.com/ElqIsk

21

Re: C ++ idea for the standard.

pkl> It a little more . It would be desirable in 1 line the built in means, without adding the . In python it is from a box.

22

Re: C ++ idea for the standard.

R>> Looked, how much difficult it turns out. It turns out not difficult and quite readably: U> at you , but it is unimportant, since works incorrectly Works correctly. Transits on all values, with possibility them to use, even if somewhere ended.

23

Re: C ++ idea for the standard.

Hello, rean, you wrote: R> Works correctly. Read the initial message more attentively to understand as it should work

24

Re: C ++ idea for the standard.

R>> Works correctly. U> read the initial message more attentively to understand as it I should work I assume that if it is necessary to walk on several vectors simultaneously then I should have control over all simultaneously. If it is necessary to quit, when any it is possible to change an output condition || on && ends. Or generally as it would be desirable and where it would be desirable. If implement it, your code will be in accuracy mine.

25

Re: C ++ idea for the standard.

Hello, pkl, you wrote: pkl> There are 3 containers: a, b, c. I want to launch 1 range-cycle on them all simultaneously: pkl> pkl> for (auto i1: a, auto i2: b, auto i3: c) {pkl>} pkl> pkl> On each iteration i1, i2, i3 has the next value from the appropriate container. pkl> the cycle dies as soon as the smallest container will be settled. Whether pkl> an ass it? I the stupid addict? Whether it is possible to make it already  without ? It becomes elementarily and sense to drag it in the standard personally I do not see. Here already recalled about zip. Still it would be possible to recall some usefulness from boost, such as iterator_range, iterator_facade, iterator_adaptor. But now I want to show, how  is simple this task dares  the language, without usage of all enumerated: https://ideone.com/HkybcL #include <functional> #include <numeric> #include <iostream> #include <tuple> #include <vector> template <typename. . T> class ZipIterator {public: using reference = std:: tuple <decltype (*std:: declval <T> ())...>; public: ZipIterator (T&&...i): m (std:: forward <T> (i)...) {}; reference operator * () const {return std:: tie (*std:: get <T> (m)...);} ZipIterator operator ++ () {char c [] {(++ std:: get <T> (m), 0)...}; return *this;} bool operator == (const ZipIterator& other) const {const bool eq [] {(std:: get <T> (m) == std:: get <T> (other.m))...}; return std:: accumulate (std:: begin (eq), std:: end (eq), false, std:: logical_or <> ());} bool operator! = (const ZipIterator& other) const {return! (*this == other);} private: std:: tuple <T...> m;}; template <typename T> struct IteratorRange {T m_begin; T m_end; const T& begin () const {return m_begin;} const T& end () const {return }; template <typename... T> using ZipRange = IteratorRange <ZipIterator <decltype (std:: begin (std:: declval <T> ()))...>>; template <typename... T> ZipRange <T...> make_zip_range (T&&...t) {return {{std:: begin (t)...}, {std:: end (t)...}};} int main () {std:: vector <int> a {1, 2, 3}; std:: vector <std:: string> b {"hello", "world", "foo", "bar"}; int c [] {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; for (auto&& entry: make_zip_range (a, b, c)) {std:: cout <<std:: get <0> (entry) <<"," <<std:: get <1> (entry) <<"," <<std:: get <2> (entry) <<std:: endl;}}