Issue 1418: C++ _var type widening proposal (cxx_revision) Source: (, ) Nature: Uncategorized Issue Severity: Summary: Summary: Michi Henning & Steve Vinoski have previously challenged people to come up with a modification to the C++ language mapping that would allow for type safe widening of object reference _var types for assignment or copy construction. I believe I have come up with the solution, and Michi agrees with me: Proposal: For object reference _var types, replace the copy and assignment operators: class T_var { public: ... T_var(const T_var &); T_var &operator = (const T_var &); ... }; with: class T_var { public: ... template <class C_var> T_var(const C_var &cv) : ptr_(T::_duplicate(cv.in()) { } template <class C_var> T_var &operator = (const C_var &cv) { if ((void *)this != (void *)cv) { CORBA::release(ptr_); ptr_ = T::_duplicate(cv.in()); } return *this; } ... private: T_ptr ptr_; }; Resolution: Revised Text: Actions taken: June 2, 1998: received issue Discussion: deferred in June 2011 to the next RTF End of Annotations:===== Return-Path: Sender: jon@floorboard.com Date: Mon, 01 Jun 1998 15:01:28 -0700 From: Jonathan Biggar To: cxx_revision@omg.org, issues@omg.org Subject: C++ _var type widening proposal Michi Henning & Steve Vinoski have previously challenged people to come up with a modification to the C++ language mapping that would allow for type safe widening of object reference _var types for assignment or copy construction. I believe I have come up with the solution, and Michi agrees with me: Proposal: For object reference _var types, replace the copy and assignment operators: class T_var { public: ... T_var(const T_var &); T_var &operator = (const T_var &); ... }; with: class T_var { public: ... template T_var(const C_var &cv) : ptr_(T::_duplicate(cv.in()) { } template T_var &operator = (const C_var &cv) { if ((void *)this != (void *)cv) { CORBA::release(ptr_); ptr_ = T::_duplicate(cv.in()); } return *this; } ... private: T_ptr ptr_; }; These member template functions will successfully compile only for object reference types (C) which inherit from the base (T) type. Caveats: This code only works for compilers that support member template functions. The implementations of the template functions are for expository purposes and can be replaced by any valid code that maintains equivalent semantics. -- Jon Biggar Floorboard Software jon@floorboard.com jon@biggar.org Return-Path: Date: Mon, 1 Jun 1998 16:11:13 -0700 (Pacific Daylight Time) From: Joachim Achtzehnter To: Jonathan Biggar cc: cxx_revision@omg.org, issues@omg.org Subject: Re: C++ _var type widening proposal X-X-Sender: joachim@ns.mercury.bc.ca On Mon, 1 Jun 1998, Jonathan Biggar wrote: > Caveats: This code only works for compilers that support member > template functions. The implementations of the template functions > are > for expository purposes and can be replaced by any valid code that > maintains equivalent semantics. Yes, and doesn't the C++ mapping claim that templates are NOT required for a compliant implementation? Seems to me that if you require template support for this part of the spec, and even "member templates"(!) at that, then templates (and the STL library) should be used to cleanup the rest of the spec as well. Makes little sense to introduce templates here and not in other places. Joachim --- joachim@kraut.bc.ca (http://www.kraut.bc.ca) joachim@mercury.bc.ca (http://www.mercury.bc.ca) Return-Path: Sender: jon@floorboard.com Date: Mon, 01 Jun 1998 17:58:20 -0700 From: Jonathan Biggar To: Joachim Achtzehnter CC: cxx_revision@omg.org Subject: Re: C++ _var type widening proposal References: Joachim Achtzehnter wrote: > > On Mon, 1 Jun 1998, Jonathan Biggar wrote: > > > Caveats: This code only works for compilers that support member > > template functions. The implementations of the template functions > are > > for expository purposes and can be replaced by any valid code that > > maintains equivalent semantics. > > Yes, and doesn't the C++ mapping claim that templates are NOT > required for > a compliant implementation? Seems to me that if you require template > support for this part of the spec, and even "member templates"(!) at > that, > then templates (and the STL library) should be used to cleanup the > rest of > the spec as well. Makes little sense to introduce templates here and > not > in other places. This seems an odd position to take. My proposal is completely backwards compatible, whereas the other cleanup (particularly using STL) would require parallel APIs or breaking existing code. True, my proposal requires support for member templates. I know of two compilers that support them now, VC++ 5.0 and HP aCC. There may be others. Besides, we already require templates for implementing the POA tie classes. -- Jon Biggar Floorboard Software jon@floorboard.com jon@biggar.org Return-Path: X-Authentication-Warning: tigger.dstc.edu.au: michi owned process doing -bs Date: Wed, 3 Jun 1998 00:25:32 +1000 (EST) From: Michi Henning To: Jonathan Biggar cc: Joachim Achtzehnter , cxx_revision@omg.org Subject: Re: C++ _var type widening proposal On Mon, 1 Jun 1998, Jonathan Biggar wrote: > > Yes, and doesn't the C++ mapping claim that templates are NOT required for > > a compliant implementation? Seems to me that if you require template > > support for this part of the spec, and even "member templates"(!) at that, > > then templates (and the STL library) should be used to cleanup the rest of > > the spec as well. Makes little sense to introduce templates here and not > > in other places. > > This seems an odd position to take. My proposal is completely backwards > compatible, whereas the other cleanup (particularly using STL) would > require parallel APIs or breaking existing code. > > True, my proposal requires support for member templates. I know of two > compilers that support them now, VC++ 5.0 and HP aCC. There may be > others. The problem I see is that if I write code that relies on widening assignments between _var references and then move that code to a different platform (but possibly for the same ORB), it may not compile any longer because the new platform's C++ compiler may not support member templates yet. I'd love to have widening _var assignments in the mapping, but I'm reluctant to add this to the mapping right now because of the lack of member template support in many compilers. Why don't we just put this on the back burner until there are more ANSI C++ compilers out there? > Besides, we already require templates for implementing the POA tie > classes. Yes. Looks like the words about not requiring template support will have to be removed from the spec. Cheers, Michi. -- Michi Henning +61 7 33654310 DSTC Pty Ltd +61 7 33654311 (fax) University of Qld 4072 michi@dstc.edu.au AUSTRALIA http://www.dstc.edu.au/BDU/staff/michi-henning.html Return-Path: Sender: jon@floorboard.com Date: Tue, 02 Jun 1998 08:09:33 -0700 From: Jonathan Biggar To: Michi Henning CC: Joachim Achtzehnter , cxx_revision@omg.org Subject: Re: C++ _var type widening proposal References: Michi Henning wrote: > The problem I see is that if I write code that relies on widening assignments > between _var references and then move that code to a different platform > (but possibly for the same ORB), it may not compile any longer because the > new platform's C++ compiler may not support member templates yet. > > I'd love to have widening _var assignments in the mapping, but I'm reluctant > to add this to the mapping right now because of the lack of member template > support in many compilers. Why don't we just put this on the back burner > until there are more ANSI C++ compilers out there? I agree with the sentiment to wait because of portability issues. I just wanted to get the proposal into the "record" so that it is there for future action. > > Besides, we already require templates for implementing the POA tie > > classes. > > Yes. Looks like the words about not requiring template support will > have > to be removed from the spec. Yup. -- Jon Biggar Floorboard Software jon@floorboard.com jon@biggar.org