Opened 11 years ago

Closed 10 years ago

#6501 closed Feature Requests (wontfix)

BOOST_STRONG_TYPEDEF Unexpected result when performing an addition (and probably other type of operators) of two strongly typed variables.

Reported by: anonymous Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

If you add two strongly typed variables of the same type result is not of the typedef type but of the underlying type.

The example below will generate a compiler error which is unexpected as I see it.

#include <boost/strong_typedef.hpp> BOOST_STRONG_TYPEDEF(int, TypedInt)

int main() {

TypedInt x(10); TypedInt y(20); TypedInt z = x + y;

return 0;

}

Change History (2)

comment:1 by viboes, 10 years ago

Component: Noneserialization
Owner: set to Robert Ramey

comment:2 by Robert Ramey, 10 years ago

Resolution: wontfix
Status: newclosed
Type: BugsFeature Requests

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.

On the other hand, one might want to really think about this.

BOOST_STRONG_TYPEDEF(int, T1); BOOST_STRONG_TYPEDEF(int, T2); BOOST_STRONG_TYPEDEF(long, T3); BOOST_STRONG_TYPEDEF(int, T4)

T1 t1; T2 t2; T2 t3; T4 t4;

So what type should t1 + t2 be? What about t1 + t3 ? Not at all clear to me. You can already do

T4 operator+(T1 t1, T3, t3){

return t1 + t3;

}

which was the original motivation for this strong type.

Of course you can resolve the issue with static_cast<T4>(t1 + t3) or any assignment

t4 = t1 + t3.

So now I think about this, I don't think it's a good idea to mess with this.

Robert Ramey

Seems to be the best course would to follow the

Note: See TracTickets for help on using tickets.