Boost C++ Libraries: Ticket #6501: BOOST_STRONG_TYPEDEF Unexpected result when performing an addition (and probably other type of operators) of two strongly typed variables. https://svn.boost.org/trac10/ticket/6501 <p> If you add two strongly typed variables of the same type result is not of the typedef type but of the underlying type. </p> <p> The example below will generate a compiler error which is unexpected as I see it. </p> <p> #include &lt;boost/strong_typedef.hpp&gt; BOOST_STRONG_TYPEDEF(int, <a class="missing wiki">TypedInt</a>) </p> <p> int main() { </p> <blockquote> <p> <a class="missing wiki">TypedInt</a> x(10); <a class="missing wiki">TypedInt</a> y(20); <a class="missing wiki">TypedInt</a> z = x + y; </p> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6501 Trac 1.4.3 viboes Mon, 28 May 2012 17:34:16 GMT component changed; owner set https://svn.boost.org/trac10/ticket/6501#comment:1 https://svn.boost.org/trac10/ticket/6501#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Robert Ramey</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">serialization</span> </li> </ul> Ticket Robert Ramey Mon, 28 May 2012 18:33:45 GMT status, type changed; resolution set https://svn.boost.org/trac10/ticket/6501#comment:2 https://svn.boost.org/trac10/ticket/6501#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> I don't think the serialization library uses this any more. Of course it's still in there. I have no idea if anyone uses it. If you want to submit a patch, I'd be happy to roll it in. </p> <p> On the other hand, one might want to really think about this. </p> <p> BOOST_STRONG_TYPEDEF(int, T1); BOOST_STRONG_TYPEDEF(int, T2); BOOST_STRONG_TYPEDEF(long, T3); BOOST_STRONG_TYPEDEF(int, T4) </p> <p> T1 t1; T2 t2; T2 t3; T4 t4; </p> <p> So what type should t1 + t2 be? What about t1 + t3 ? Not at all clear to me. You can already do </p> <p> T4 operator+(T1 t1, T3, t3){ </p> <blockquote> <p> return t1 + t3; </p> </blockquote> <p> } </p> <p> which was the original motivation for this strong type. </p> <p> Of course you can resolve the issue with static_cast&lt;T4&gt;(t1 + t3) or any assignment </p> <p> t4 = t1 + t3. </p> <p> So now I think about this, I don't think it's a good idea to mess with this. </p> <p> Robert Ramey </p> <p> Seems to be the best course would to follow the </p> Ticket