From 8091141a73af14487dbf52a48e09aaca4256e13f Mon Sep 17 00:00:00 2001 From: nasos Date: Wed, 9 Apr 2014 19:47:17 -0400 Subject: [PATCH] Fixed some gcc 4.8 issues in C++11 mode with index_pair and index_triple --- changelog.txt | 1 + include/boost/numeric/ublas/storage.hpp | 29 +++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/changelog.txt b/changelog.txt index b8ebe8ce..c51aecdd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ Version 1.1.0 index_triple_array to allow proper compilation of sparse containers with g++>4.8 (4.7 also?) in C++11 mode. + 02 Apr. 2014 Nasos Iliopoulos * Added changelog diff --git a/include/boost/numeric/ublas/storage.hpp b/include/boost/numeric/ublas/storage.hpp index d43c1ab8..41f649d1 100644 --- a/include/boost/numeric/ublas/storage.hpp +++ b/include/boost/numeric/ublas/storage.hpp @@ -1607,11 +1607,17 @@ namespace boost { namespace numeric { namespace ublas { rhs = *this; *this = tmp; } + BOOST_UBLAS_INLINE friend void swap(self_type& lhs, self_type& rhs) { lhs.swap(rhs); } + friend void swap(self_type lhs, self_type rhs) { // For gcc 4.8 and c++11 + lhs.swap(rhs); + } + + BOOST_UBLAS_INLINE bool equal(const self_type& rhs) const { return (v1_ == rhs.v1_); @@ -1727,11 +1733,12 @@ namespace boost { namespace numeric { namespace ublas { std::swap(lhs().data2_[i1], rhs().data2_[i2]); } - // This refers to index_pair<>&, but [gcc4.8, C++11] can't deduce the type to correctly dispatch the swap - // Fixme: find a more elegant solution BOOST_UBLAS_INLINE - friend void swap( typename iterator::reference lhs, typename iterator::reference rhs) { // This referes to index_pair<>&, but gcc4.8 can't deduce the type to correctly dispatch the swap - lhs.swap(rhs); + friend void iter_swap(iterator& lhs, const iterator& rhs) { + const size_type i1 = lhs.index(); + const size_type i2 = rhs.index(); + std::swap(lhs().data1_[i1], rhs().data1_[i2]); + std::swap(lhs().data2_[i1], rhs().data2_[i2]); } private: @@ -1780,16 +1787,21 @@ namespace boost { namespace numeric { namespace ublas { } BOOST_UBLAS_INLINE - void swap(self_type& rhs) { + void swap(self_type& rhs) { // Fixme: Should this be deprecated? self_type tmp(rhs); rhs = *this; *this = tmp; } + BOOST_UBLAS_INLINE friend void swap(self_type& lhs, self_type& rhs) { lhs.swap(rhs); } + friend void swap(self_type lhs, self_type rhs) { // For gcc 4.8 and c++11 + lhs.swap(rhs); + } + BOOST_UBLAS_INLINE bool equal(const self_type& rhs) const { return ((v1_ == rhs.v1_) && (v2_ == rhs.v2_)); @@ -1910,13 +1922,6 @@ namespace boost { namespace numeric { namespace ublas { std::swap(lhs().data3_[i1], rhs().data3_[i2]); } - // This refers to index_pair<>&, but [gcc4.8, C++11] can't deduce the type to correctly dispatch the swap - // Fixme: find a more elegant solution - BOOST_UBLAS_INLINE - friend void swap( typename iterator::reference lhs, typename iterator::reference rhs) { - lhs.swap(rhs); - } - private: size_type size_; V1& data1_;