Opened 7 years ago

Closed 6 years ago

#5491 closed Bugs (fixed)

invalid result for user defined type

Reported by: Akira Takahashi <faithandbrave@…> Owned by: Eric Niebler
Milestone: To Be Determined Component: accumulator
Version: Boost 1.46.1 Severity: Problem
Keywords: Cc:


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;

    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;




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.

Attachments (2)

functional.patch (1.7 KB) - added by Akira Takahashi <faithandbrave@…> 7 years ago.
add check numeric_limits::is_specialized
functional.hpp (21.6 KB) - added by Akira Takahashi <faithandbrave@…> 7 years ago.
patched source

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by Akira Takahashi <faithandbrave@…>

Attachment: functional.patch added

add check numeric_limits::is_specialized

Changed 7 years ago by Akira Takahashi <faithandbrave@…>

Attachment: functional.hpp added

patched source

comment:1 Changed 6 years ago by Eric Niebler

Resolution: fixed
Status: newclosed

(In [74477]) merge [74476] from trunk, fixes #5491

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Eric Niebler.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.