Subject: [Boost-bugs] [Boost C++ Libraries] #5491: invalid result for user defined type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-04-20 02:25:10
#5491: invalid result for user defined type
-------------------------------------------------------+--------------------
Reporter: Akira Takahashi <faithandbrave@â¦> | Owner: eric_niebler
Type: Bugs | Status: new
Milestone: To Be Determined | Component: accumulator
Version: Boost 1.46.1 | Severity: Problem
Keywords: |
-------------------------------------------------------+--------------------
`min` is invalid result for user defined type.
{{{
#include <iostream>
#include <limits>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
using namespace boost::accumulators;
struct integer {
int x;
integer() : x(0) {}
integer(int x) : x(x) {}
integer& operator+=(integer other)
{
std::cout << "+=,";
x += other.x;
return *this;
}
};
/*
namespace std {
template <>
struct numeric_limits<integer> {
static const bool is_specialized = true;
static ::integer max() { return std::numeric_limits<int>::max(); }
};
}
*/
bool operator<(integer a, integer b)
{
std::cout << "<,";
return a.x < b.x;
}
int main()
{
accumulator_set<integer, stats<tag::min, tag::sum> > acc;
std::cout << "add:" << std::endl;
acc(1);
acc(2);
acc(3);
std::cout << std::endl;
std::cout << "extract:" << std::endl;
const integer a = extract::min(acc);
const integer b = extract::sum(acc);
std::cout << std::endl;
std::cout << "result:" << std::endl;
std::cout << a.x << std::endl;
std::cout << b.x << std::endl;
}
}}}
result:
{{{
add:
<,+=,<,+=,<,+=,
extract:
result:
0
6
}}}
`min` result should be 1.
This problem is integer type non specialize std::numeric_limits.
Should check std::numeric_limits::is_specialized.
I send patch.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5491> 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:06 UTC