From 25033804023fb961721503f354d72b87ba4eafba Mon Sep 17 00:00:00 2001 From: Kevin Hopps Date: Thu, 5 Oct 2017 14:13:21 -0500 Subject: [PATCH] Cleanup: Silence Xcode 8.2.1 warnings. --- .../numeric/ublas/detail/matrix_assign.hpp | 8 +- include/boost/numeric/ublas/exception.hpp | 11 +- .../boost/numeric/ublas/matrix_expression.hpp | 32 +++-- include/boost/numeric/ublas/matrix_sparse.hpp | 110 +++++++++++++----- .../boost/numeric/ublas/vector_of_vector.hpp | 76 ++++++++---- include/boost/numeric/ublas/vector_sparse.hpp | 11 +- 6 files changed, 177 insertions(+), 71 deletions(-) diff --git a/include/boost/numeric/ublas/detail/matrix_assign.hpp b/include/boost/numeric/ublas/detail/matrix_assign.hpp index b6de2586f..8b81877a3 100644 --- a/include/boost/numeric/ublas/detail/matrix_assign.hpp +++ b/include/boost/numeric/ublas/detail/matrix_assign.hpp @@ -978,8 +978,8 @@ namespace detail { #ifdef _MSC_VER #pragma warning(pop) #endif - BOOST_UBLAS_CHECK (m.size1 () == e ().size1 (), bad_size ()); - BOOST_UBLAS_CHECK (m.size2 () == e ().size2 (), bad_size ()); + BOOST_UBLAS_CHECK (m.size1 () == static_cast(e ().size1 ()), bad_size ()); + BOOST_UBLAS_CHECK (m.size2 () == static_cast(e ().size2 ()), bad_size ()); typedef typename M::value_type value_type; // Sparse type has no numeric constraints to check @@ -997,7 +997,9 @@ namespace detail { while (it2e != it2e_end) { value_type t (*it2e); if (t != value_type/*zero*/()) - m.insert_element (it2e.index1 (), it2e.index2 (), t); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + m.insert_element (static_cast(it2e.index1 ()), static_cast(it2e.index2 ()), t); ++ it2e; } ++ it1e; diff --git a/include/boost/numeric/ublas/exception.hpp b/include/boost/numeric/ublas/exception.hpp index 5354298d1..2e42f3473 100644 --- a/include/boost/numeric/ublas/exception.hpp +++ b/include/boost/numeric/ublas/exception.hpp @@ -17,6 +17,7 @@ #endif #include +#include // needed for make_unsigned namespace boost { namespace numeric { namespace ublas { @@ -271,8 +272,14 @@ namespace boost { namespace numeric { namespace ublas { // We better change the signature instead of libcomo ;-) // const T &same_impl_ex (const T &size1, const T &size2, const char *file, int line) { T1 same_impl_ex (const T1 &size1, const T2 &size2, const char *file, int line) { - BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ()); - return (size1 < size2)?(size1):(size2); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const unsigned long' to 'int' + typedef typename std::make_unsigned::type UT1; + typedef typename std::make_unsigned::type UT2; + UT1 usize1 = static_cast(size1); + UT2 usize2 = static_cast(size2); + BOOST_UBLAS_CHECK_EX (usize1 == usize2, file, line, bad_argument ()); + return static_cast(usize1 < usize2 ? size1 : size2); } template BOOST_UBLAS_INLINE diff --git a/include/boost/numeric/ublas/matrix_expression.hpp b/include/boost/numeric/ublas/matrix_expression.hpp index 8e6c2f68b..879ca6fdd 100644 --- a/include/boost/numeric/ublas/matrix_expression.hpp +++ b/include/boost/numeric/ublas/matrix_expression.hpp @@ -2066,11 +2066,13 @@ namespace boost { namespace numeric { namespace ublas { // Element lookup BOOST_UBLAS_INLINE const_iterator1 find1 (int rank, size_type i, size_type j) const { - const_iterator11_type it11 (e1_.find1 (rank, i, j)); - const_iterator11_type it11_end (e1_.find1 (rank, size1 (), j)); - const_iterator21_type it21 (e2_.find1 (rank, i, j)); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_iterator11_type it11 (e1_.find1 (rank, static_cast(i), static_cast(j))); + const_iterator11_type it11_end (e1_.find1 (rank, static_cast(size1 ()), static_cast(j))); + const_iterator21_type it21 (e2_.find1 (rank, static_cast(i), static_cast(j))); const_iterator21_type it21_end (e2_.find1 (rank, size1 (), j)); - BOOST_UBLAS_CHECK (rank == 0 || it11 == it11_end || it11.index2 () == j, internal_logic ()) + BOOST_UBLAS_CHECK (rank == 0 || it11 == it11_end || static_cast(it11.index2 ()) == j, internal_logic ()) BOOST_UBLAS_CHECK (rank == 0 || it21 == it21_end || it21.index2 () == j, internal_logic ()) i = (std::min) (it11 != it11_end ? it11.index1 () : size1 (), it21 != it21_end ? it21.index1 () : size1 ()); @@ -2082,11 +2084,13 @@ namespace boost { namespace numeric { namespace ublas { } BOOST_UBLAS_INLINE const_iterator2 find2 (int rank, size_type i, size_type j) const { - const_iterator12_type it12 (e1_.find2 (rank, i, j)); - const_iterator12_type it12_end (e1_.find2 (rank, i, size2 ())); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_iterator12_type it12 (e1_.find2 (rank, static_cast(i), static_cast(j))); + const_iterator12_type it12_end (e1_.find2 (rank, static_cast(i), static_cast(size2 ()))); const_iterator22_type it22 (e2_.find2 (rank, i, j)); const_iterator22_type it22_end (e2_.find2 (rank, i, size2 ())); - BOOST_UBLAS_CHECK (rank == 0 || it12 == it12_end || it12.index1 () == i, internal_logic ()) + BOOST_UBLAS_CHECK (rank == 0 || it12 == it12_end || static_cast(it12.index1 ()) == i, internal_logic ()) BOOST_UBLAS_CHECK (rank == 0 || it22 == it22_end || it22.index1 () == i, internal_logic ()) j = (std::min) (it12 != it12_end ? it12.index2 () : size2 (), it22 != it22_end ? it22.index2 () : size2 ()); @@ -2215,7 +2219,9 @@ namespace boost { namespace numeric { namespace ublas { void increment (sparse_bidirectional_iterator_tag) { size_type index1 = (*this) ().size1 (); if (it1_ != it1_end_) { - if (it1_.index1 () <= i_) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (static_cast(it1_.index1 ()) <= i_) ++ it1_; if (it1_ != it1_end_) index1 = it1_.index1 (); @@ -2566,7 +2572,9 @@ namespace boost { namespace numeric { namespace ublas { void increment (sparse_bidirectional_iterator_tag) { size_type index1 = (*this) ().size2 (); if (it1_ != it1_end_) { - if (it1_.index2 () <= j_) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (static_cast(it1_.index2 ()) <= j_) ++ it1_; if (it1_ != it1_end_) index1 = it1_.index2 (); @@ -2624,8 +2632,10 @@ namespace boost { namespace numeric { namespace ublas { value_type dereference (sparse_bidirectional_iterator_tag) const { typename E1::value_type t1 = typename E1::value_type/*zero*/(); if (it1_ != it1_end_) { - BOOST_UBLAS_CHECK (it1_.index1 () == i_, internal_logic ()); - if (it1_.index2 () == j_) + BOOST_UBLAS_CHECK (static_cast(it1_.index1 ()) == i_, internal_logic ()); + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'const size_type' (aka 'const unsigned long') + if (static_cast(it1_.index2 ()) == j_) t1 = *it1_; } typename E2::value_type t2 = typename E2::value_type/*zero*/(); diff --git a/include/boost/numeric/ublas/matrix_sparse.hpp b/include/boost/numeric/ublas/matrix_sparse.hpp index d9677540d..6d7ed683f 100644 --- a/include/boost/numeric/ublas/matrix_sparse.hpp +++ b/include/boost/numeric/ublas/matrix_sparse.hpp @@ -2838,7 +2838,9 @@ namespace boost { namespace numeric { namespace ublas { size1_ (0), size2_ (0), capacity_ (restrict_capacity (0)), filled1_ (1), filled2_ (0), index1_data_ (layout_type::size_M (size1_, size2_) + 1), index2_data_ (capacity_), value_data_ (capacity_) { - index1_data_ [filled1_ - 1] = k_based (filled2_); + // Silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + index1_data_ [filled1_ - 1] = k_based (static_cast(filled2_)); storage_invariants (); } BOOST_UBLAS_INLINE @@ -2887,11 +2889,15 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE compressed_matrix (const matrix_expression &ae, size_type non_zeros = 0): matrix_container (), - size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), capacity_ (restrict_capacity (non_zeros)), + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + size1_ (static_cast(ae ().size1 ())), size2_ (static_cast(ae ().size2 ())), capacity_ (restrict_capacity (non_zeros)), filled1_ (1), filled2_ (0), index1_data_ (layout_type::size_M (ae ().size1 (), ae ().size2 ()) + 1), index2_data_ (capacity_), value_data_ (capacity_) { - index1_data_ [filled1_ - 1] = k_based (filled2_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + index1_data_ [filled1_ - 1] = k_based (static_cast(filled2_)); storage_invariants (); matrix_assign (*this, ae); } @@ -2983,13 +2989,17 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (!preserve, internal_logic ()); size1_ = size1; size2_ = size2; - capacity_ = restrict_capacity (capacity_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + capacity_ = restrict_capacity (static_cast(capacity_)); filled1_ = 1; filled2_ = 0; index1_data_.resize (layout_type::size_M (size1_, size2_) + 1); index2_data_.resize (capacity_); value_data_.resize (capacity_); - index1_data_ [filled1_ - 1] = k_based (filled2_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + index1_data_ [filled1_ - 1] = k_based (static_cast(filled2_)); storage_invariants (); } @@ -3007,7 +3017,9 @@ namespace boost { namespace numeric { namespace ublas { value_data_.resize (capacity_); filled1_ = 1; filled2_ = 0; - index1_data_ [filled1_ - 1] = k_based (filled2_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + index1_data_ [filled1_ - 1] = k_based (static_cast(filled2_)); } storage_invariants (); } @@ -3019,9 +3031,11 @@ namespace boost { namespace numeric { namespace ublas { } BOOST_UBLAS_INLINE const_pointer find_element (size_type i, size_type j) const { - size_type element1 (layout_type::index_M (i, j)); - size_type element2 (layout_type::index_m (i, j)); - if (filled1_ <= element1 + 1) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'const array_size_type' (aka 'const unsigned long') and 'int' + size_type element1 (static_cast(layout_type::index_M (i, j))); + size_type element2 (static_cast(layout_type::index_m (i, j))); + if (static_cast(filled1_) <= element1 + 1) return 0; vector_const_subiterator_type itv (index1_data_.begin () + element1); const_subiterator_type it_begin (index2_data_.begin () + zero_based (*itv)); @@ -3063,12 +3077,16 @@ namespace boost { namespace numeric { namespace ublas { true_reference insert_element (size_type i, size_type j, const_reference t) { BOOST_UBLAS_CHECK (!find_element (i, j), bad_index ()); // duplicate element if (filled2_ >= capacity_) - reserve (2 * filled2_, true); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'unsigned long' to 'size_type' (aka 'int') + reserve (static_cast(2 * filled2_), true); BOOST_UBLAS_CHECK (filled2_ < capacity_, internal_logic ()); - size_type element1 = layout_type::index_M (i, j); - size_type element2 = layout_type::index_m (i, j); - while (filled1_ <= element1 + 1) { - index1_data_ [filled1_] = k_based (filled2_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + size_type element1 = static_cast(layout_type::index_M (i, j)); + size_type element2 = static_cast(layout_type::index_m (i, j)); + while (static_cast(filled1_) <= element1 + 1) { + index1_data_ [filled1_] = k_based (static_cast(filled2_)); ++ filled1_; } vector_subiterator_type itv (index1_data_.begin () + element1); @@ -3084,7 +3102,9 @@ namespace boost { namespace numeric { namespace ublas { typename value_array_type::iterator itt (value_data_.begin () + n); std::copy_backward (itt, value_data_.begin () + filled2_ - 1, value_data_.begin () + filled2_); *itt = t; - while (element1 + 1 < filled1_) { + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'int' and 'array_size_type' (aka 'unsigned long') + while (element1 + 1 < static_cast(filled1_)) { ++ index1_data_ [element1 + 1]; ++ element1; } @@ -3124,7 +3144,9 @@ namespace boost { namespace numeric { namespace ublas { void clear () { filled1_ = 1; filled2_ = 0; - index1_data_ [filled1_ - 1] = k_based (filled2_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + index1_data_ [filled1_ - 1] = k_based (static_cast(filled2_)); storage_invariants (); } @@ -3147,7 +3169,9 @@ namespace boost { namespace numeric { namespace ublas { template // Container assignment without temporary BOOST_UBLAS_INLINE compressed_matrix &operator = (const matrix_container &m) { - resize (m ().size1 (), m ().size2 (), false); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + resize (static_cast(m ().size1 ()), static_cast(m ().size2 ()), false); assign (m); return *this; } @@ -3309,10 +3333,14 @@ namespace boost { namespace numeric { namespace ublas { const_subiterator_type it_begin (index2_data_.begin () + zero_based (*itv)); const_subiterator_type it_end (index2_data_.begin () + zero_based (*(itv + 1))); - const_subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (address2), std::less ())); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (static_cast(address2)), std::less ())); if (rank == 0) return const_iterator1 (*this, rank, i, j, itv, it); - if (it != it_end && zero_based (*it) == address2) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'array_size_type' (aka 'unsigned long') + if (it != it_end && zero_based (*it) == static_cast(address2)) return const_iterator1 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_i ()) { @@ -3349,10 +3377,14 @@ namespace boost { namespace numeric { namespace ublas { subiterator_type it_begin (index2_data_.begin () + zero_based (*itv)); subiterator_type it_end (index2_data_.begin () + zero_based (*(itv + 1))); - subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (address2), std::less ())); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (static_cast(address2)), std::less ())); if (rank == 0) return iterator1 (*this, rank, i, j, itv, it); - if (it != it_end && zero_based (*it) == address2) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'array_size_type' (aka 'unsigned long') + if (it != it_end && zero_based (*it) == static_cast(address2)) return iterator1 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_i ()) { @@ -3389,10 +3421,14 @@ namespace boost { namespace numeric { namespace ublas { const_subiterator_type it_begin (index2_data_.begin () + zero_based (*itv)); const_subiterator_type it_end (index2_data_.begin () + zero_based (*(itv + 1))); - const_subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (address2), std::less ())); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'array_size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_subiterator_type it (detail::lower_bound (it_begin, it_end, k_based (static_cast(address2)), std::less ())); if (rank == 0) return const_iterator2 (*this, rank, i, j, itv, it); - if (it != it_end && zero_based (*it) == address2) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'array_size_type' (aka 'unsigned long') + if (it != it_end && zero_based (*it) == static_cast(address2)) return const_iterator2 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_j ()) { @@ -3585,8 +3621,10 @@ namespace boost { namespace numeric { namespace ublas { size_type index1 () const { BOOST_UBLAS_CHECK (*this != (*this) ().find1 (0, (*this) ().size1 (), j_), bad_index ()); if (rank_ == 1) { - BOOST_UBLAS_CHECK (layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)) < (*this) ().size1 (), bad_index ()); - return layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + BOOST_UBLAS_CHECK (static_cast(layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))) < (*this) ().size1 (), bad_index ()); + return static_cast(layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))); } else { return i_; } @@ -3594,8 +3632,10 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE size_type index2 () const { if (rank_ == 1) { - BOOST_UBLAS_CHECK (layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)) < (*this) ().size2 (), bad_index ()); - return layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)); + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'size_type' (aka 'int') + BOOST_UBLAS_CHECK (static_cast(layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))) < (*this) ().size2 (), bad_index ()); + return static_cast(layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))); } else { return j_; } @@ -3929,8 +3969,10 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE size_type index1 () const { if (rank_ == 1) { - BOOST_UBLAS_CHECK (layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)) < (*this) ().size1 (), bad_index ()); - return layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + BOOST_UBLAS_CHECK (static_cast(layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))) < (*this) ().size1 (), bad_index ()); + return static_cast(layout_type::index_M (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))); } else { return i_; } @@ -3939,8 +3981,10 @@ namespace boost { namespace numeric { namespace ublas { size_type index2 () const { BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ()); if (rank_ == 1) { - BOOST_UBLAS_CHECK (layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)) < (*this) ().size2 (), bad_index ()); - return layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_)); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + BOOST_UBLAS_CHECK (static_cast(layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))) < (*this) ().size2 (), bad_index ()); + return static_cast(layout_type::index_m (itv_ - (*this) ().index1_data_.begin (), (*this) ().zero_based (*it_))); } else { return j_; } @@ -4230,7 +4274,9 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_CHECK (capacity_ == value_data_.size (), internal_logic ()); BOOST_UBLAS_CHECK (filled1_ > 0 && filled1_ <= layout_type::size_M (size1_, size2_) + 1, internal_logic ()); BOOST_UBLAS_CHECK (filled2_ <= capacity_, internal_logic ()); - BOOST_UBLAS_CHECK (index1_data_ [filled1_ - 1] == k_based (filled2_), internal_logic ()); + // Silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const array_size_type' (aka 'const unsigned long') to 'size_type' (aka 'int') + BOOST_UBLAS_CHECK (index1_data_ [filled1_ - 1] == k_based (static_cast(filled2_)), internal_logic ()); } size_type size1_; diff --git a/include/boost/numeric/ublas/vector_of_vector.hpp b/include/boost/numeric/ublas/vector_of_vector.hpp index de87a668a..f20639021 100644 --- a/include/boost/numeric/ublas/vector_of_vector.hpp +++ b/include/boost/numeric/ublas/vector_of_vector.hpp @@ -140,18 +140,29 @@ namespace boost { namespace numeric { namespace ublas { const size_type sizem = layout_type::size_m (size1_, size2_); data ().resize (sizeM + 1, preserve); if (preserve) { - for (size_type i = 0; (i <= oldM) && (i < sizeM); ++ i) - ref (data () [i]).resize (sizem, preserve); - for (size_type i = oldM+1; i < sizeM; ++ i) // create new vector elements - data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false); + for (size_type i = 0; (i <= oldM) && (i < sizeM); ++ i) { + // Qualify ref to silence Xcode 8.2.1: + // error: call to 'ref' is ambiguous + boost::numeric::ublas::ref(data()[i]).resize (static_cast(sizem), preserve); + } + for (size_type i = oldM+1; i < sizeM; ++ i) { // create new vector elements + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const size_type' (aka 'const unsigned long') to 'size_type' (aka 'int') + data_.insert_element (i, vector_data_value_type ()) .resize (static_cast(sizem), false); + } if (sizeM > oldM) { data_.insert_element (sizeM, vector_data_value_type ()); } else { - ref (data () [sizeM]).resize (0, false); + // Qualify ref to silence Xcode 8.2.1: + // error: call to 'ref' is ambiguous + boost::numeric::ublas::ref (data()[sizeM]).resize (0, false); } } else { - for (size_type i = 0; i < sizeM; ++ i) - data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false); + for (size_type i = 0; i < sizeM; ++ i) { + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const size_type' (aka 'const unsigned long') to 'size_type' (aka 'int') + data_.insert_element (i, vector_data_value_type ()) .resize (static_cast(sizem), false); + } data_.insert_element (sizeM, vector_data_value_type ()); } storage_invariants (); @@ -174,7 +185,9 @@ namespace boost { namespace numeric { namespace ublas { const typename array_type::value_type *pv = data ().find_element (elementM); if (!pv) return 0; - return pv->find_element (elementm); + // Silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const size_type' (aka 'const unsigned long') to 'size_type' (aka 'int') + return pv->find_element (static_cast(elementm)); } } @@ -298,9 +311,13 @@ namespace boost { namespace numeric { namespace ublas { true_reference insert_element (size_type i, size_type j, const_reference t) { const size_type elementM = layout_type::index_M (i, j); const size_type elementm = layout_type::index_m (i, j); - vector_data_value_type& vd (ref (data () [elementM])); + // Qualify ref to silence Xcode 8.2.1: + // error: call to 'ref' is ambiguous + vector_data_value_type& vd (boost::numeric::ublas::ref (data () [elementM])); storage_invariants (); - return vd.insert_element (elementm, t); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'const size_type' (aka 'const unsigned long') to 'size_type' (aka 'int') + return vd.insert_element (static_cast(elementm), t); } BOOST_UBLAS_INLINE void append_element (size_type i, size_type j, const_reference t) { @@ -322,8 +339,11 @@ namespace boost { namespace numeric { namespace ublas { void clear () { const size_type sizeM = layout_type::size_M (size1_, size2_); // FIXME should clear data () if this is done via value_type/*zero*/() then it is not size preserving - for (size_type i = 0; i < sizeM; ++ i) - ref (data () [i]).clear (); + for (size_type i = 0; i < sizeM; ++ i) { + // Qualify ref to silence Xcode 8.2.1: + // error: call to 'ref' is ambiguous + boost::numeric::ublas::ref (data()[i]).clear (); + } storage_invariants (); } @@ -359,11 +379,15 @@ namespace boost { namespace numeric { namespace ublas { if (itv == itv_end) return const_iterator1 (*this, rank, i, j, itv_end, (*(-- itv)).end ()); - const_subiterator_type it ((*itv).find (layout_type::index_m (i, j))); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_subiterator_type it ((*itv).find (static_cast(layout_type::index_m (i, j)))); const_subiterator_type it_end ((*itv).end ()); if (rank == 0) return const_iterator1 (*this, rank, i, j, itv, it); - if (it != it_end && it.index () == layout_type::index_m (i, j)) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (it != it_end && it.index () == static_cast(layout_type::index_m (i, j))) return const_iterator1 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_i ()) { @@ -397,11 +421,15 @@ namespace boost { namespace numeric { namespace ublas { if (itv == itv_end) return iterator1 (*this, rank, i, j, itv_end, (*(-- itv)).end ()); - subiterator_type it ((*itv).find (layout_type::index_m (i, j))); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + subiterator_type it ((*itv).find (static_cast(layout_type::index_m (i, j)))); subiterator_type it_end ((*itv).end ()); if (rank == 0) return iterator1 (*this, rank, i, j, itv, it); - if (it != it_end && it.index () == layout_type::index_m (i, j)) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (it != it_end && it.index () == static_cast(layout_type::index_m (i, j))) return iterator1 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_i ()) { @@ -435,11 +463,15 @@ namespace boost { namespace numeric { namespace ublas { if (itv == itv_end) return const_iterator2 (*this, rank, i, j, itv_end, (*(-- itv)).end ()); - const_subiterator_type it ((*itv).find (layout_type::index_m (i, j))); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + const_subiterator_type it ((*itv).find (static_cast(layout_type::index_m (i, j)))); const_subiterator_type it_end ((*itv).end ()); if (rank == 0) return const_iterator2 (*this, rank, i, j, itv, it); - if (it != it_end && it.index () == layout_type::index_m (i, j)) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (it != it_end && it.index () == static_cast(layout_type::index_m (i, j))) return const_iterator2 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_j ()) { @@ -473,11 +505,15 @@ namespace boost { namespace numeric { namespace ublas { if (itv == itv_end) return iterator2 (*this, rank, i, j, itv_end, (*(-- itv)).end ()); - subiterator_type it ((*itv).find (layout_type::index_m (i, j))); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + subiterator_type it ((*itv).find (static_cast(layout_type::index_m (i, j)))); subiterator_type it_end ((*itv).end ()); if (rank == 0) return iterator2 (*this, rank, i, j, itv, it); - if (it != it_end && it.index () == layout_type::index_m (i, j)) + // Use static_cast to silence Xcode 8.2.1: + // error: comparison of integers of different signs: 'size_type' (aka 'int') and 'size_type' (aka 'unsigned long') + if (it != it_end && it.index () == static_cast(layout_type::index_m (i, j))) return iterator2 (*this, rank, i, j, itv, it); if (direction > 0) { if (layout_type::fast_j ()) { diff --git a/include/boost/numeric/ublas/vector_sparse.hpp b/include/boost/numeric/ublas/vector_sparse.hpp index 134a62061..5258c7c82 100644 --- a/include/boost/numeric/ublas/vector_sparse.hpp +++ b/include/boost/numeric/ublas/vector_sparse.hpp @@ -953,7 +953,9 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE void resize (size_type size, bool preserve = true) { size_ = size; - capacity_ = restrict_capacity (capacity_); + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'typename index_array_type::size_type' (aka 'unsigned long') to 'size_type' (aka 'int') + capacity_ = restrict_capacity (static_cast(capacity_)); if (preserve) { index_data_. resize (capacity_, size_type ()); value_data_. resize (capacity_, value_type ()); @@ -1041,8 +1043,11 @@ namespace boost { namespace numeric { namespace ublas { BOOST_UBLAS_INLINE true_reference insert_element (size_type i, const_reference t) { BOOST_UBLAS_CHECK (!find_element (i), bad_index ()); // duplicate element - if (filled_ >= capacity_) - reserve (2 * capacity_, true); + if (filled_ >= capacity_) { + // Use static_cast to silence Xcode 8.2.1: + // error: implicit conversion loses integer precision: 'unsigned long' to 'size_type' (aka 'int') + reserve (static_cast(2 * capacity_), true); + } subiterator_type it (detail::lower_bound (index_data_.begin (), index_data_.begin () + filled_, k_based (i), std::less ())); // ISSUE max_capacity limit due to difference_type typename std::iterator_traits::difference_type n = it - index_data_.begin ();