Subject: [Boost-bugs] [Boost C++ Libraries] #3543: Example code using Boost accumulators fails to compile with GCC 4.4.1 (Fedora 11)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-10-22 13:24:54
#3543: Example code using Boost accumulators fails to compile with GCC 4.4.1
(Fedora 11)
-------------------------------------------------------+--------------------
Reporter: Denis Arnaud <denis.arnaud_boost@â¦> | Owner: eric_niebler
Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: accumulator
Version: Boost 1.39.0 | Severity: Problem
Keywords: accumulator template tag moment |
-------------------------------------------------------+--------------------
File: boost_1_39_0/libs/accumulators/example/main.cpp
#include <iostream>
#include <algorithm>
#include <boost/ref.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>
#include <boost/foreach.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
using namespace boost;
using namespace boost::accumulators;
// Helper that uses BOOST_FOREACH to display a range of doubles
template<typename Range>
void output_range(Range const &rng)
{
bool first = true;
BOOST_FOREACH(double d, rng)
{
if(!first) std::cout << ", ";
std::cout << d;
first = false;
}
std::cout << '\n';
}
///////////////////////////////////////////////////////////////////////////////
// example1
//
// Calculate some useful stats using accumulator_set<> and
std::for_each()
//
void example1()
{
accumulator_set<
double
, stats<tag::min, tag::mean(immediate), tag::sum, tag::moment<2> >
> acc;
boost::array<double, 4> data = {0., 1., -1., 3.14159};
// std::for_each pushes each sample into the accumulator one at a
// time, and returns a copy of the accumulator.
acc = std::for_each(data.begin(), data.end(), acc);
// The following would be equivalent, and could be more efficient
// because it doesn't pass and return the entire accumulator set
// by value.
//std::for_each(data.begin(), data.end(), bind<void>(ref(acc), _1));
std::cout << " min(acc) = " << (min)(acc) << std::endl;
std::cout << " mean(acc) = " << mean(acc) << std::endl;
// since mean depends on count and sum, we can get their results, too.
std::cout << " count(acc) = " << count(acc) << std::endl;
std::cout << " sum(acc) = " << sum(acc) << std::endl;
std::cout << " moment<2>(acc) = " << '''moment<2>'''(acc) <<
std::endl;
}
----
Result of the compilation attempt:
Scanning dependencies of target accumulators-accumulators_example
Building CXX object libs/accumulators/example/CMakeFiles/accumulators-
accumulators_example.dir/main.cpp.o
/home/build/dev/fedorasvn/reviews/boost_529563/boost_1_39_0_working/boost/accumulators/statistics_fwd.hpp:
In function âvoid example1()â:
/home/build/dev/fedorasvn/reviews/boost_529563/boost_1_39_0_working/boost/accumulators/statistics_fwd.hpp:87:
error: âtemplate<int N> struct boost::accumulators::tag::momentâ is not a
function,
/home/build/dev/fedorasvn/reviews/boost_529563/boost_1_39_0_working/boost/accumulators/statistics/moment.hpp:104:
error: conflict with âtemplate<int T2, class Arg1, class A0, class A1,
class A2, class A3, class A4, class A5, class A6, class A7, class A8,
class A9, class A10, class A11, class A12, class A13, class A14> typename
boost::accumulators::detail::extractor_result<Arg1,
boost::accumulators::tag::moment<T2> >::type
boost::accumulators::extract::moment(const Arg1&, const A0&, const A1&,
const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const
A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const
A14&)â
/home/build/dev/fedorasvn/reviews/boost_529563/boost_1_39_0_working/libs/accumulators/example/main.cpp:63:
error: in call to âmomentâ
make[2]: *** [libs/accumulators/example/CMakeFiles/accumulators-
accumulators_example.dir/main.cpp.o] Error 1
make[1]: *** [libs/accumulators/example/CMakeFiles/accumulators-
accumulators_example.dir/all] Error 2
make: *** [all] Error 2
----
Suggested patch (which fixes that compilation problem):
diff -ru --exclude=Makefile --exclude=CMakeFiles
--exclude=cmake_install.cmake
boost_1_39_0/libs/accumulators/example/main.cpp
boost_1_39_0_working/libs/accumulators/example/main.cpp
--- boost_1_39_0/libs/accumulators/example/main.cpp 2008-06-20
05:47:42.000000000 +0200
+++ boost_1_39_0_working/libs/accumulators/example/main.cpp 2009-10-22
14:51:29.000000000 +0200
@@ -14,7 +14,6 @@
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
-using namespace boost;
using namespace boost::accumulators;
// Helper that uses BOOST_FOREACH to display a range of doubles
@@ -60,7 +59,7 @@
// since mean depends on count and sum, we can get their results,
too.
std::cout << " count(acc) = " << count(acc) << std::endl;
std::cout << " sum(acc) = " << sum(acc) << std::endl;
- std::cout << " moment<2>(acc) = " << moment<2>(acc) << std::endl;
+ std::cout << " moment<2>(acc) = " <<
boost::accumulators::moment<2>(acc) << std::endl;
}
///////////////////////////////////////////////////////////////////////////////
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3543> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC