Boost C++ Libraries: Ticket #10829: cardinality() of an interval_set is std::size_t independent of interval type, causing overflow https://svn.boost.org/trac10/ticket/10829 <p> For an interval_set boost::icl::interval_set&lt;int64_t&gt;, the cardinality function boost::icl::cardinality() returns std::size_t, which is 32-bit on 32-bit machines. This makes the result wrong, due to overflow, whenever the cardinality of the interval_set does not fit into 32-bit. </p> <p> The following code works on 64-bit but not on 32-bit: </p> <pre class="wiki">#include &lt;boost/icl/interval_set.hpp&gt; int main() { boost::icl::interval_set&lt;int64_t&gt; is; is.add(boost::icl::interval&lt;int64_t&gt;::closed(1, 4294967297LL)); assert(boost::icl::cardinality(is) == 4294967297LL); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10829 Trac 1.4.3 bugs@… Mon, 01 Dec 2014 10:47:41 GMT <link>https://svn.boost.org/trac10/ticket/10829#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10829#comment:1</guid> <description> <p> Out of curiosity, SFINAE-ing the <code>get_size_type</code> trait for arithmetic or integral types does seem to do what's expected. </p> <p> I'm aware of the fact that following code is not up to coding standards and Boost guides. I'm just contributing it in case it saves anyone else time during analysis: </p> <p> Replace </p> <pre class="wiki">template &lt;class Type&gt; struct get_size_type&lt;Type, false, false, false&gt; { typedef std::size_t type; }; </pre><p> with </p> <pre class="wiki">template &lt;class Type&gt; struct get_size_type&lt;Type, std::enable_if&lt;not boost::is_arithmetic&lt;Type&gt;::value, mpl::false_&gt;::type::value, false, false&gt; { typedef std::size_t type; }; template &lt;class Type&gt; struct get_size_type&lt;Type, std::enable_if&lt;boost::is_arithmetic&lt;Type&gt;::value, mpl::false_&gt;::type::value, false, false&gt; { typedef typename std::common_type&lt;Type, std::size_t&gt;::type type; }; </pre> </description> <category>Ticket</category> </item> </channel> </rss>