How to workaround this tree implementation that breaks with Sun studio

F

Fei Liu

Hello Group,

we have a template tree implementation that breaks on SunOS based on
#5, #6 in this note:
http://developers.sun.com/sunstudio/documentation/ss12u1/mr/READMEs/c++_faq.html#LibComp

The relevant code segment is this:

template <class Key>
struct _Tree_base_iterator
{
typedef typename TreeNode<Key>::base_ptr base_ptr;
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
base_ptr node;

void increment()
{
if (node->right != 0) {
node = node->right;
while (node->left != 0)
node = node->left;
}
else {
base_ptr y = node->parent;
while (node == y->right) {
node = y;
y = y->parent;
}
if (node->right != y)
node = y;
}
}
void increment()
{}
}

template <class TT, typename Ref, typename Ptr, typename Key>
struct _Tree_iterator : public _Tree_base_iterator<Key>
{
typedef TT value_type;
typedef Ref reference;
typedef Ptr pointer;
typedef _Tree_iterator iterator;
typedef _Tree_iterator<TT, const TT&, const TT*, Key> const_iterator;
typedef _Tree_iterator<TT, Ref, Ptr, Key> self;
typedef TreeNode<Key>* link_type;

_Tree_iterator() {}
_Tree_iterator(link_type x) { this->node = x; }
_Tree_iterator(const iterator& it) { this->node = it.node; }

reference operator*() const { return
static_cast<reference>(*this->node); }
pointer operator->() const { return &(operator*()); }

self& operator++() { this->increment(); return *this; }
self operator++(int) {
self tmp = *this;
this->increment();
return tmp;
}

self& operator--() { this->decrement(); return *this; }
self operator--(int) {
self tmp = *this;
this->decrement();
return tmp;
}
};

template <class Key, class TT, class Compare = std::less<Key> >
class Tree {
protected:
typedef void* void_pointer;
typedef TreeNode<Key>* base_ptr;
typedef _Tree_color_type color_type;
public:
typedef Key key_type;
typedef TT value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef TreeNode<Key>* link_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;

typedef _Tree_iterator<value_type, reference, pointer, Key> iterator;
typedef _Tree_iterator<value_type, const_reference, const_pointer, Key>
const_iterator;

typedef std::reverse_iterator<value_type, const_reference,
const_pointer, Key> const_reverse_iterator;
typedef std::reverse_iterator<value_type, reference, pointer, Key>
reverse_iterator;

}

Sun studio compiler has trouble with the reverse_iterator and
const_reverse_iterator typedefs,
Error: Too few arguments for template
std::reverse_iterator<ESMCI::_Tree_iterator<ESMCI::TT, const
ESMCI::TT&, const ESMCI::TT*, ESMCI::Key>>

This code works with standard conforming libraries. I am looking for
ideas that work around the Sun studio library problem. Let me know if
you need more info about this. Thanks,

Fei
 
F

Fei Liu

Ian said:
Compiles fine on my system.

CC -V
CC: Sun C++ 5.9 SunOS_i386 Patch 124864-12 2009/04/21

<snip code>
Ian, the library is standard conforming after version 5.1. We are
working with a compiler version prior to 5.0. We know the code works on
standard conforming STL implementation and compilers.
 
I

Ian Collins

Fei said:
Ian, the library is standard conforming after version 5.1. We are
working with a compiler version prior to 5.0. We know the code works on
standard conforming STL implementation and compilers.

Then the generic answer to anyone using pre-standard compilers applies -
upgrade!
 
F

Fei Liu

Ian said:
Then the generic answer to anyone using pre-standard compilers applies -
upgrade!
We would love to but it's not going to help us in this case, at least in
the short term. Is there a way to work around this member template
constraints in this case?

Fei
 
F

Fei Liu

Hendrik said:
Fei said:
Ian Collins wrote:
[...]
Then the generic answer to anyone using pre-standard compilers
applies - upgrade!
We would love to but it's not going to help us in this case, at least
in the short term. Is there a way to work around this member template
constraints in this case?

You might have a better chance to get help if you could distill
this down into a small, self-contained example, that compiles
on std-conforming compilers and post the error messages your
compiler gives, indicating the exact lines.
Also, VC5 didn't have member templates (and, AFIK, any partial
specialization) and therefor shipped with a std lib which had
this disabled. And (AFAIK for legal reasons) VC6 shipped with
the same std lib and also had a lot of missing or buggy template
features. You might find hints and workarounds in std lib
implementations created for these compilers and postings
regarding their shortcommings.

Schobi

Thanks, it looks like this is not something obvious why this is failing.
We'll do some more digging on our side first. We may just swap to an
alternative tree implementation.

Fei
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top