3

我尝试compressed_matrix使用 acoordinate_matrix作为构建器创建一个:

#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>

using namespace boost::numeric::ublas;

int main(int argc, char** argv) {
  coordinate_matrix<int> m1(100, 100, 100);

  for (int i = 0; i < 100; i++)
    m1.insert_element(i,i,i);

  compressed_matrix<int> m2(m1, 100);
}

使用 boost 1.54 和 clang 似乎可以正常工作,但是当我使用 std=c++11 编译它时,会引发错误:

 choeger@daishi /tmp % clang++ test.cpp --std=c++11
In file included from test.cpp:1:
In file included from /usr/include/boost/numeric/ublas/io.hpp:18:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/sstream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/istream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/ios:40:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/char_traits.h:39:
/usr/bin/../lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/bits/stl_algobase.h:147:7: error: no matching function for call to 'swap'
      swap(*__a, *__b);

是否存在已知的 boost 1.54 与 C++11 的不兼容性?还是我犯了一些 C++11 错误?1.55 的更新日志没有提到 ublas 和矩阵,所以我猜它仍然存在。

这发生在 gcc 4.8.2 和 clang 3.4

4

2 回答 2

3

这绝对是 Boost 中的一个错误。问题是 whenBOOST_UBLAS_STRICT_MATRIX_SPARSE被定义,coordinate_matrix它的迭代器类型使用代理类作为它们的reference类型:

#ifndef BOOST_UBLAS_STRICT_MATRIX_SPARSE
        typedef T &reference;
#else
        typedef sparse_matrix_element<self_type> reference;
#endif

这违反了 C++ 标准的要求,即reference前向迭代器的类型是真正的引用。C++11 [forward.iterators]/1 声明:“一个类或指针类型X满足前向迭代器的要求,如果 ... ifX是可变迭代器,reference是对 的引用T;如果Xconst迭代器,reference是对const T,……”。

尽管有这个coordinate_matrix事实,迭代器仍声称是双向迭代器,从而导致未定义的行为。

于 2014-06-16T15:05:18.187 回答
1

回答我自己的问题:

感谢@cv_and_he 的评论,我认为C++ 参考的以下部分在这里是相关的(因为coordinate_matrix调用std::sort):

随机访问迭代器到要排序的序列的初始和最终位置。使用的范围是 [first,last),它包含 first 和 last 之间的所有元素,包括 first 指向的元素,但不包括 last 指向的元素。RandomAccessIterator 应该指向一个正确定义了 swap并且既可以移动构造又可以移动赋值的类型。

显然,swap 方法没有正确定义(不管这意味着什么)。

错误报告在这里

于 2014-06-16T08:57:56.373 回答