|
Boost Users : |
Subject: Re: [Boost-users] [multi_array] std::swap and subarray
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-02-20 00:38:43
> I think this solves the problem, (except for the fact that there it
> may be a more efficient way by swapping element by element).
complete code:
-- #include<boost/multi_array.hpp> namespace std { template <typename TValue, boost::detail::multi_array::size_type K> void swap( boost::detail::multi_array::sub_array<TValue, K> lhs, boost::detail::multi_array::sub_array<TValue, K> rhs) { boost::multi_array<TValue, K> tmp = lhs; lhs = rhs; rhs = tmp; } } // namespace std #include<iostream> int main(){ boost::multi_array<double, 2> a; a.resize( boost::extents[2][2] ); for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) a[i][j] = (i+1)*10 + j+1; // a[0].swap(a[1]); std::swap( a[0], a[1] ); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) std::cout << a[i][j] << " "; std::cout << std::endl; } return 0; } --
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net