Modify

Ticket #3543 (closed Bugs: fixed)

Opened 4 years ago

Last modified 4 years ago

Example code using Boost accumulators fails to compile with GCC 4.4.1 (Fedora 11)

Reported by: Denis Arnaud <denis.arnaud_boost@…> Owned by: eric_niebler
Milestone: Boost 1.41.0 Component: accumulator
Version: Boost 1.39.0 Severity: Problem
Keywords: accumulator template tag moment Cc:

Description

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;

}

/

Attachments

boost-accumulators-namespace-fix.patch Download (1.1 KB) - added by Denis Arnaud <denis.arnaud_boost@…> 4 years ago.
Patch for the compilation issue on the accumulator's example

Change History

comment:1 Changed 4 years ago by eric_niebler

  • Status changed from new to closed
  • Resolution set to fixed

This has already been fixed on the release branch. Thanks for the report.

Changed 4 years ago by Denis Arnaud <denis.arnaud_boost@…>

Patch for the compilation issue on the accumulator's example

comment:2 follow-up: ↓ 3 Changed 4 years ago by Stefan van Kessel <van_kessel@…>

The fix applied was faulty. Either using namespace boost; has to be added, too or moment has to be fully qualified like boost::accumulators::moment. Right now there's only using namespace boost::accumulators; and moment is qualified accumulators::moment which fails because the namespace accumulators is not available at that scope.

It's a minor issue but the fix is so easy that I think it's worth applying. --- accumulators.qbk (revision 65571) +++ accumulators.qbk (working copy) @@ -101,7 +101,7 @@

Display the results ... std::cout << "Mean: " << mean(acc) << std::endl;

  • std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;

+ std::cout << "Moment: " << boost::accumulators::moment<2>(acc) << std::endl;

return 0;

}

comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 4 years ago by denis.arnaud_boost@…

Replying to Stefan van Kessel <van_kessel@…>:

  • std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;

+ std::cout << "Moment: " << boost::accumulators::moment<2>(acc) << std::endl;

Sorry, but in the  patch, (Boost) accumulators::moment() was already fully qualified.

comment:4 in reply to: ↑ 3 Changed 4 years ago by Stefan van Kessel <van_kessel@…>

Replying to denis.arnaud_boost@…:

Replying to Stefan van Kessel <van_kessel@…>:

  • std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;

+ std::cout << "Moment: " << boost::accumulators::moment<2>(acc) << std::endl;

Sorry, but in the  patch, (Boost) accumulators::moment() was already fully qualified.

Yes, your original patch is correct. Thank you. I meant to refer to the fix that actually made it into the repository.  http://svn.boost.org/svn/boost/trunk/libs/accumulators/doc/accumulators.qbk still uses "accumulators::moment<2>(acc)".

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.