Boost C++ Libraries: Ticket #5491: invalid result for user defined type https://svn.boost.org/trac10/ticket/5491 <p> <code>min</code> is invalid result for user defined type. </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;limits&gt; #include &lt;boost/accumulators/accumulators.hpp&gt; #include &lt;boost/accumulators/statistics.hpp&gt; using namespace boost::accumulators; struct integer { int x; integer() : x(0) {} integer(int x) : x(x) {} integer&amp; operator+=(integer other) { std::cout &lt;&lt; "+=,"; x += other.x; return *this; } }; /* namespace std { template &lt;&gt; struct numeric_limits&lt;integer&gt; { static const bool is_specialized = true; static ::integer max() { return std::numeric_limits&lt;int&gt;::max(); } }; } */ bool operator&lt;(integer a, integer b) { std::cout &lt;&lt; "&lt;,"; return a.x &lt; b.x; } int main() { accumulator_set&lt;integer, stats&lt;tag::min, tag::sum&gt; &gt; acc; std::cout &lt;&lt; "add:" &lt;&lt; std::endl; acc(1); acc(2); acc(3); std::cout &lt;&lt; std::endl; std::cout &lt;&lt; "extract:" &lt;&lt; std::endl; const integer a = extract::min(acc); const integer b = extract::sum(acc); std::cout &lt;&lt; std::endl; std::cout &lt;&lt; "result:" &lt;&lt; std::endl; std::cout &lt;&lt; a.x &lt;&lt; std::endl; std::cout &lt;&lt; b.x &lt;&lt; std::endl; } </pre><p> result: </p> <pre class="wiki">add: &lt;,+=,&lt;,+=,&lt;,+=, extract: result: 0 6 </pre><p> <code>min</code> result should be 1. </p> <p> This problem is integer type non specialize std::numeric_limits. Should check std::numeric_limits::is_specialized. </p> <p> I send patch. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5491 Trac 1.4.3 Akira Takahashi <faithandbrave@…> Wed, 20 Apr 2011 02:25:55 GMT attachment set https://svn.boost.org/trac10/ticket/5491 https://svn.boost.org/trac10/ticket/5491 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">functional.patch</span> </li> </ul> <p> add check numeric_limits::is_specialized </p> Ticket Akira Takahashi <faithandbrave@…> Wed, 20 Apr 2011 02:27:18 GMT attachment set https://svn.boost.org/trac10/ticket/5491 https://svn.boost.org/trac10/ticket/5491 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">functional.hpp</span> </li> </ul> <p> patched source </p> Ticket Eric Niebler Tue, 20 Sep 2011 02:59:11 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5491#comment:1 https://svn.boost.org/trac10/ticket/5491#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/74477" title="merge [74476] from trunk, fixes #5491">[74477]</a>) merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/74476" title="statically assert that std::numeric_limits is specialized">[74476]</a> from trunk, fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5491" title="#5491: Bugs: invalid result for user defined type (closed: fixed)">#5491</a> </p> Ticket