fork download
  1. #include <algorithm>
  2. #include <array>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. #define WIDTH 3
  8. #define HEIGHT 2
  9.  
  10. int main() {
  11. const array<array<int, HEIGHT>, WIDTH> pCells = { 1, 2, 11, 12, 21, 22 };
  12. int lCells[WIDTH * HEIGHT];
  13.  
  14. for_each(begin(lCells), end(lCells), [i = cbegin(pCells), j = cbegin(pCells)->cbegin()](auto& it) mutable {
  15. if(j == i->cend()) j = (++i)->cbegin();
  16.  
  17. it = *j++;
  18. });
  19.  
  20. for(const auto& i : lCells) {
  21. cout << i << ' ';
  22. }
  23. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1 2 11 12 21 22