Boost :: аккумулятор: STD :: вектор не работает с Rolling_mean

Я следую за какой-то веткой (этот, этот а также этот), чтобы вычислить скользящее среднее, используя std :: vector в качестве образца.

Я включил заголовки numeric::functional сабиблиотека для работы с векторами

Этот код не компилируется

#include <cstdlib>
#include <boost/accumulators/numeric/functional/vector.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
#include <boost/unordered_map.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/assign/list_of.hpp>

using namespace std;
using namespace boost::accumulators;

typedef accumulator_set<vector<float>, tag::rolling_mean> RollingMeanAccumulator;
typedef boost::shared_ptr<RollingMeanAccumulator> RollingMeanAccumulatorPtr;

int main(int argc, char** argv) {

RollingMeanAccumulatorPtr ptr = RollingMeanAccumulatorPtr(new RollingMeanAccumulator(vector<float>(2), tag::rolling_window::window_size = 4));
const vector<float> v = boost::assign::list_of(2.0)(3.0);
(*ptr)(v);
rolling_mean(*(ptr));

return 0;
}

Вместо этого он компилируется, если я прокомментирую эту строку

rolling_mean(*(ptr));

Таким образом, кажется, что есть проблема в получении значения. Как я могу это исправить?

Я использую Boost 1.48.

РЕДАКТИРОВАТЬ:

@doctorlove заметил в ошибке компиляции, что operator-= скучает по std::Vector, Я открыла boost/accumulators/numeric/functional/vector.hpp и я видел, что определение этого оператора отсутствует. Поэтому я добавил его в свой код, изменив его таким образом (извините, если он не очень хорошо написан):

#include <cstdlib>
#include <boost/accumulators/numeric/functional/vector.hpp>

namespace boost { namespace numeric { namespace operators {
template<typename Left>
std::vector<Left> &
operator -=(std::vector<Left> &left, std::vector<Left> const &right)
{
BOOST_ASSERT(left.size() == right.size());
for(std::size_t i = 0, size = left.size(); i != size; ++i)
{
numeric::minus_assign(left[i], right[i]);
}
return left;
}
}}}#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
#include <boost/unordered_map.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/assign/list_of.hpp>

using namespace std;
using namespace boost::accumulators;

typedef accumulator_set<vector<float>, tag::rolling_mean> RollingMeanAccumulator;
typedef boost::shared_ptr<RollingMeanAccumulator> RollingMeanAccumulatorPtr;

int main(int argc, char** argv) {

RollingMeanAccumulatorPtr ptr = RollingMeanAccumulatorPtr(new RollingMeanAccumulator(vector<float>(2), tag::rolling_window::window_size = 4));
const vector<float> v = boost::assign::list_of(2.0)(3.0);
(*ptr)(v);
rolling_mean(*(ptr));

return 0;
}

Я взял определение operator+= в этом заголовке и адаптировал его.

Я делаю так, потому что в эта почта пользователь говорит, что векторные операторы должны быть определены до определения аккумулятора.

Но даже в этом случае я не могу его скомпилировать.

1

Решение

Задача ещё не решена.

Другие решения