
Ok, now I see I don't really understand how stl handles types with reference semantics. Looks like std::swap should be overloaded. Maybe stl algorithms shouldn't be used with such types at all?
I also felt hesitant of overloading std::swap by value, instead as the generic template that uses references... On one hand, std::swap is meant to be overloaded in certain circumstances, but changing the input type? I don't know. on the other hand: it works, and it does what is supposed to do for sub_arrays, and it also seems to work in more generic circumstances (under std::random_shuffle), so what? If it works it is the right thing. In any case I would be more worried about defining the overload of std::swap with the right implementation by swapping element by element, instead of creating a huge temporary array. If you figure out that code, please paste it here. By the way, now that I am thinking about it, the std::swap of subarray that we defined should work recursively so we can use the std::swap inside our std::swap for each subsubarray of the subarray. If it is an element (not another subsubarray) still will do the right thing. ah! generic code is so beautiful! That leads me to think that we are doing something that not only works but also that we are doing it in right way. Alfredo