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:
Now, if Fruit is a SLICE class with at least one method, because slice2cpp translates SLICE class methods to pure virtual methods in C++. If you instantiate the template, it will generate fun expressions like "sizeof(Fruit)" in it's memory allocation code which won't compile because Fruit is abstract.Here is the definition of our FruitPlatter sequence from Section 4.9.3 once more:
sequence<Fruit> FruitPlatter;
The Slice compiler generates the following C++ definition for the FruitPlatter sequence:
typedef std::vector<Fruit> FruitPlatter;
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?

Reply With Quote
.
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.