
Le 20/10/11 09:43, Robert Ramey a écrit :
Vicent -
I saw your post on this subject some months ago and I've reviewed the thread. I didn't look at the code though. I also looked at the C++0x document and I have something to say about this.
a) as you know I'm the author of BOOST_STRONG_TYPEDEF which lets one assign a unique type to some primitive integer type. I did this to permit overloads on integers used for different purposes. The new types created had all the properties of integer types but they were all different types. So far so good.
b) I eventually found the BOOST_STRONG_TYPEDEF did too much - what I really wanted to not to inherit all the interoperations but only some of them. So I've reduced or eliminated usage of BOOST_STRONG_TYPE from the serialization library implementation. Never the less, I do see it useful in other contexts so your efforts to create and opaque typedef seem useful to me.
c) BUT now I really want something else. I want the ability to assign a new type to an existing type. The current typedef has the feature that if two different names are used for the same type, a new type is NOT created. That is typedef creates a synonym rather than a new type. I thought that C++0x template alias would do this. But a careful reading of the standard document that I have leads me to believe that if two names are aliased to the same underlying type - a new type is not created - just like the current typedef. So what we have in the new C++ is basically a templated typedef.
d) what I really need is the equivalent to
#define OPAQUE_TYPEDEF(name, t) \ struct name : public t {};
so I can say
struct dollar_amount { ... operator *(const& rhs) const {..} // don't include this operator - makes no sense };
OPAQUE_TYPEDEF(debit, dollar_amount); OPAQUE_TYPEDEF(price, dollar_amount)
and then say void f(debit, t){...} void f(price t){...}
Notice in my example, I don't want debit and price types to be true types and not just synonyms for dollar_amount.
I realize that this is whole different kettle of fixh than BOOST_STRONG_TYPE or OPAQUE_TYPE. So this might be considered off topic. or maybe not.
Comments welcome. Also anyone can feel free to correct my understanding of the template alias feature of C++0x to create new types. Hi,
there is a feature in C++11 that could respond to your needs. |struct debit :|dollar_amount | { using|||dollar_amount|::|||dollar_amount|; }; | This paper http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2141.html explain its relation to Opaque types. Best, Vicente