1

There is the following type

 template <typename T>
 using TL = std::vector<T>;

How to create a multiple/based range loop over two variables

 TL <double> l1, l2;     
 for ( auto a:l1, auto b:l2)

instead of using

 TL::iterator = il1, il2;
 for (il1 = l1. begin(), il2=l2.begin();;)

Thanks for your help...

justik
  • 4,145
  • 6
  • 32
  • 53
  • You can't do that. – molbdnilo Jul 01 '16 at 13:00
  • You could use BOOST_FOREACH and [zip_iterator](http://www.boost.org/doc/libs/1_46_0/libs/iterator/doc/zip_iterator.html) – coincoin Jul 01 '16 at 13:01
  • There is no such thing in `C++`, anyway, If it was what would happen when one `vector` will be shorter than another? The best option is to use nested for-range loops. – PcAF Jul 01 '16 at 13:02
  • 1
    Also https://stackoverflow.com/questions/12552277/whats-the-best-way-to-iterate-over-two-or-more-containers-simultaneously – Baum mit Augen Jul 01 '16 at 13:02
  • 1
    @PcAF: No, such a thing may be easily constructed in C++, and nested for-range loops are not only not "the best option" but they won't even do what is being asked for. – Lightness Races in Orbit Jul 01 '16 at 13:03
  • @ Baum : Thanks, I missed the thread... – justik Jul 01 '16 at 13:07
  • @LightnessRaceInOrbit I've just read linked question, first answers states that if their length is not the same it causes undefined behaviour (in some specific version, I'm not sure about ofther versions). Nested loops will be slow and redudant, I agree, I just made a ....(ehm.. (big mistake)) – PcAF Jul 01 '16 at 13:21

0 Answers0