|
|
|
|||||
|
Documentation Bug and suggestion for C++ sequences
Hi ZeroC developers,
I'm relatively new to both this forum and to using ICE, but a seasoned programmer of almost 10 years in OOP languages and particularly Delphi/C++. I was looking over another post here which deals with polymorphic sequences. While thinking this over, I realised that the documented SLICE to C++ mappings for sequences couldn't possibly be correct. Section 6.7.3 of the ICE user manual states: Quote:
Anyhow, I ran slice2cpp (as shipped in ICE version 3.2.1) to see what typedef it actually created. The typedef it actually generates is (after performing typedef substitution): "typedef std::vector<IceInternal::Handle<Fruit> > FruitPlatter" IceInternal::Handle is by the look of things a reference-counted smart pointer class, and like most smart pointer classes the * and -> operators are defined to return references and pointers. Can I suggest the documentation be modified to explain how sequences are actually mapped to C++? Anyhow, that typedef suggests that polymorphic sequences should work, though the syntax will be different to that in Java/C#. The elements of C++ sequences are pointers while in Java/C# the elements are effectively references. That means in Java/C# you access members with ".", and with "->" in C++. On a secondary point, you could instead use a "smart pointer container" template similar to the one in boost (see here). What ptr_container does is similar to a vector of smart pointers, except you'd declare it as ptr_container_vector<Fruit> and the accessor methods and iterators return references instead of pointers. ptr_container is STL-compatible and there's a pretty good chance it will become part of the STL in the future, due to a number of Boost's members also being on the ISO C++ standards committee. At any rate, I believe their licenses are compatible with yours, but I could be wrong. IMO, that would provide the same sorts of guarantees as your smart pointer class, while retaining the more natural "." member access used in the other languages. Unfortunately, I would guess this is one of those things that are hard to change due to backward-compatibility issues. Maybe this could be something for a major release? |
|
||||||
|
Quote:
Quote:
Quote:
Quote:
Cheers, Michi. |
|
|||||
|
Quote:
.Quote:
.And yes, I can understand why the syntax would be different - if you want to support polymorphic collections, your choices are to use either a vector of references (which won't compile due to the reference-to-reference issue in C++) or a vector to some kind of pointer. Quote:
Hm yeah, fair enough. Even barring compatibility issues, there's library versioning to think about as well. The idea behind boost: tr_container was while its a container of smart pointers, its interface is defined so that you use it in the way you would use a std::vector<T&> - if it actually compiled. That would bring the syntax for using sequences in C++ into line with the other languages.Quote:
I wonder, is it possible to achieve what I'm after using the ["cpp:type:"] tag in SLICE? I'm guessing no, since there are probably bits of the C++ ICE implementation that expect expressions like "sequence[i]" to return something pointer-like instead of something reference-like. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Suggestion on Slice documentation | n2503v | Comments | 4 | 08-07-2006 02:33 AM |
| Documentation suggestion | mwilson | Comments | 0 | 04-12-2006 05:20 PM |
| Bug in documentation | acbell | Bug Reports | 1 | 02-24-2006 05:29 PM |
| sequences syntax | panic | Help Center | 1 | 12-04-2003 09:55 AM |
| suggestion 1 | xiehua | Comments | 0 | 11-22-2003 09:53 PM |