How to workaround this tree implementation that breaks with Sun studio
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