
Hi Sergey, Ultimately, the problem is the compiler I think.
I've got somehow unexpected behaviour of std::swap with multi_array's subarray. For example, given a 2x2 multi_array: ... std::swap( a[0], a[1] );
With msvc 2008 + boost 1.42, one of the rows overwrites the other and the output is:
21 22 21 22
The problem is that a[0] and a[1] are temporary objects, and they cannot be swapped in the std::swap sense (since it takes two reference to non-const). fortunately gcc 4 catches this problem and your original code doesn't compile. Then using your hack doesn't work either (i.e. doesn't compile in gcc 4)
template
void swap( boost::detail::multi_array::sub_array &lhs, boost::detail::multi_array::sub_array &rhs)
...because of the same reason.
Well, probably that's not a problem for now, but I dunno if it's a bug or std::swap is not supported - coundn't find anything about this.
it is a (conceptual) bug in your compiler that allows you to take a
temporary as a non-const reference. (gcc wins for the conceptual
superiority this time).
Now, to solve your problem with the smallest change possible you can
try with
template