1

嗨,我正在尝试使用 boost.range 添加两个标准向量,但我得到了一堆错误。

这有效:

  std::transform(a.begin(),a.end(),b.begin(),a.begin(),std::plus<double>());

这不会:

  boost::transform(a,b,a,std::plus<double>());

有一个错误:

In file included from /usr/local/include/boost/range/algorithm.hpp:80:0,
                 from /home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.h:15,
                 from /home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.cc:1:
/usr/local/include/boost/range/algorithm/transform.hpp: In function ‘OutputIterator boost::range_detail::transform_impl(SinglePassTraversalReadableIterator1, SinglePassTraversalReadableIterator1, SinglePassTraversalReadableIterator2, SinglePassTraversalReadableIterator2, OutputIterator, BinaryFunction) [with SinglePassTraversalReadableIterator1 = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >, SinglePassTraversalReadableIterator2 = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >, OutputIterator = std::vector<double>, BinaryFunction = std::plus<double>]’:
/usr/local/include/boost/range/algorithm/transform.hpp:90:33:   instantiated from ‘OutputIterator boost::range::transform(const SinglePassRange1&, const SinglePassRange2&, OutputIterator, BinaryOperation) [with SinglePassRange1 = std::vector<double>, SinglePassRange2 = std::vector<double>, OutputIterator = std::vector<double>, BinaryOperation = std::plus<double>]’
/home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.cc:9:45:   instantiated from here
/usr/local/include/boost/range/algorithm/transform.hpp:64:17: error: no match for ‘operator*’ in ‘*out’
/usr/local/include/boost/range/algorithm/transform.hpp:64:17: note: candidates are:
/usr/include/c++/4.6/complex:399:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const std::complex<_Tp>&)
/usr/include/c++/4.6/complex:390:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const _Tp&)
/usr/include/c++/4.6/complex:381:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const std::complex<_Tp>&)
/usr/local/include/boost/range/algorithm/transform.hpp:65:17: error: no match for ‘operator++’ in ‘++out’
/usr/local/include/boost/range/algorithm/transform.hpp:65:17: note: candidate is:
/usr/local/include/boost/iterator/iterator_facade.hpp:722:3: note: template<class I, class V, class TC, class R, class D> typename boost::detail::postfix_increment_result<I, V, R, TC>::type boost::operator++(boost::iterator_facade<Derived, V, TC, R, D>&, int)

这也不是:

  std::vector<double> c;
  boost::transform(a,b,c,std::plus<double>());

有一个错误:

In file included from /usr/local/include/boost/range/algorithm.hpp:80:0,
                 from /home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.h:15,
                 from /home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.cc:1:
/usr/local/include/boost/range/algorithm/transform.hpp: In function ‘OutputIterator boost::range_detail::transform_impl(SinglePassTraversalReadableIterator1, SinglePassTraversalReadableIterator1, SinglePassTraversalReadableIterator2, SinglePassTraversalReadableIterator2, OutputIterator, BinaryFunction) [with SinglePassTraversalReadableIterator1 = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >, SinglePassTraversalReadableIterator2 = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >, OutputIterator = std::vector<double>, BinaryFunction = std::plus<double>]’:
/usr/local/include/boost/range/algorithm/transform.hpp:90:33:   instantiated from ‘OutputIterator boost::range::transform(const SinglePassRange1&, const SinglePassRange2&, OutputIterator, BinaryOperation) [with SinglePassRange1 = std::vector<double>, SinglePassRange2 = std::vector<double>, OutputIterator = std::vector<double>, BinaryOperation = std::plus<double>]’
/home/kirill/Dropbox/work/projects/doing/quasiclass/dev/source/simple_pcet.cc:8:45:   instantiated from here
/usr/local/include/boost/range/algorithm/transform.hpp:64:17: error: no match for ‘operator*’ in ‘*out’
/usr/local/include/boost/range/algorithm/transform.hpp:64:17: note: candidates are:
/usr/include/c++/4.6/complex:399:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const std::complex<_Tp>&)
/usr/include/c++/4.6/complex:390:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const _Tp&)
/usr/include/c++/4.6/complex:381:5: note: template<class _Tp> std::complex<_Tp> std::operator*(const std::complex<_Tp>&, const std::complex<_Tp>&)
/usr/local/include/boost/range/algorithm/transform.hpp:65:17: error: no match for ‘operator++’ in ‘++out’
/usr/local/include/boost/range/algorithm/transform.hpp:65:17: note: candidate is:
/usr/local/include/boost/iterator/iterator_facade.hpp:722:3: note: template<class I, class V, class TC, class R, class D> typename boost::detail::postfix_increment_result<I, V, R, TC>::type boost::operator++(boost::iterator_facade<Derived, V, TC, R, D>&, int)
4

1 回答 1

3

您的问题是第三个参数 toboost::transform不是范围,而是用于将结果写入的(输出)迭代器。

以下代码为我编译:

boost::transform ( a, b, a.begin(), std::plus<double>());
于 2013-01-21T15:55:48.760 回答