[Re:Opaque Typedef] observations on opaque typedef

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. Robert Ramey

On 10/20/2011 09:43 AM, Robert Ramey wrote:
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.
How is it not exactly the same thing? You want to create a new type that, for all practical purposes, is the same as the original one, but that can be specialized and overloaded on.
Comments welcome. Also anyone can feel free to correct my understanding of the template alias feature of C++0x to create new types.
The point of template alias is indeed to create an alias, not a new type. It has nothing to do with a so-called "strong typedef".

Mathias Gaunard wrote:
On 10/20/2011 09:43 AM, Robert Ramey wrote:
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.
How is it not exactly the same thing?
a) BOOST_STRONG_TYPE and OPAQUE_TYPE presumes that the base type is supports all integer operations while what I'm looking for doesn't make that presumption. c) the new "using ..." creates an alias rather than a new type so this is totall different than BOOST_STRONG_TYPE and OPAQUE_TYPE
You want to create a new type that, for all practical purposes, is the same as the original one, but that can be specialized and overloaded on.
correct.
The point of template alias is indeed to create an alias, not a new type. It has nothing to do with a so-called "strong typedef".
lol - that's my point. Confusion arises when one googles C++ opaque type. This raises a number of papers which address the subject but seem to suggest that the "template alias" feature will create a new type. But a careful reading of the latest documents suggest that this is not the case. This is the motivation for my question. Of course one define a macro #define NEW_OPAQUE_TYPE(new_name, current_type) \ struct new_name : public current_type {}; but I haven't really considered all the implications of this in depth. To summarize, I expected to find a new feature in C++0X but found something else - now I'm wondering what I missed. Robert Ramey

On Thu, 20 Oct 2011 08:45:04 -0800 "Robert Ramey" <ramey@rrsd.com> wrote:
[...] To summarize, I expected to find a new feature in C++0X but found something else - now I'm wondering what I missed.
As I understand it, opaque typedefs *were* on the list for C++0x, but were dropped (probably for lack of time). I was disappointed by that too. -- Chad Nelson Oak Circle Software, Inc. * * *

on Thu Oct 20 2011, "Robert Ramey" <ramey-AT-rrsd.com> wrote:
Confusion arises when one googles C++ opaque type. This raises a number of papers which address the subject but seem to suggest that the "template alias" feature will create a new type. But a careful reading of the latest documents suggest that this is not the case.
Correct. It's a new name for the same type.
This is the motivation for my question.
Of course one define a macro
#define NEW_OPAQUE_TYPE(new_name, current_type) \ struct new_name : public current_type {};
but I haven't really considered all the implications of this in depth.
To summarize, I expected to find a new feature in C++0X but found something else - now I'm wondering what I missed.
I don't think you missed anything. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On 10/20/2011 06:45 PM, Robert Ramey wrote:
Of course one define a macro
#define NEW_OPAQUE_TYPE(new_name, current_type) \ struct new_name : public current_type {};
but I haven't really considered all the implications of this in depth.
To summarize, I expected to find a new feature in C++0X but found something else - now I'm wondering what I missed.
Maybe you missed this: #define NEW_OPAQUE_TYPE(new_name, current_type) \ struct new_name : current_type \ { \ using current_type::current_type; \ }; The 'using' here is is a new C++11 feature that is useful for defining strong typedefs.

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

Vicente J. Botet Escriba wrote:
Le 20/10/11 09:43, Robert Ramey a écrit :
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.
Good information. To me, you're proposal above looks quite interesting. It also looks to be a whole different thing than BOOST_STRONG_TYPEDEF, OPAQUE_TYPE. And the paper above uses strong_typedef for something more akin to you're proposal above. It seems to be that this is a ripe subject to get sorted out and that a boost library would be a good vehicle for doing this. your OPAQUE_TYPE proposal would be part of this. We'd end up with a couple of "things" which might or might not be related. Robert Ramey
participants (5)
-
Chad Nelson
-
Dave Abrahams
-
Mathias Gaunard
-
Robert Ramey
-
Vicente J. Botet Escriba