views:

331

answers:

0

I am having trouble using smart pointers in boost intrusive containers.

According to the documentation the requirements for using smart pointers with intrusive containers are the following:

  • It must support the same operations as a raw pointer, except casting.
  • It must be convertible to a raw pointer and constructible from a raw pointer.
  • It must have the same ownership semantics as a raw pointer. This means that resource management smart pointers (like boost::shared_ptr) can't be used.

There is no mention of implementation of std::iterator_traits anywhere, however when I try to instantiate an instance of the following typedef (Handle<> is my smart pointer):

typedef boost::intrusive::list_base_hook< boost::intrusive::link_mode< boost::intrusive::safe_link >,
               boost::intrusive::void_pointer< Handle<void> >
               > ComponentBaseHook;

I get an error:

/usr/include/c++/4.3/bits/stl_iterator_base_types.h:133: error: no type named ‘iterator_category’ in ‘class Ztk::Handle’

Here is the declaration of Handle:

template<typename T>
class Handle
{
    friend class Memory;
  public:
    typedef T targetType;

    Handle(void);
    explicit Handle(T * data);

    template<typename Y>
    Handle(const Handle<Y> & rhs);

    T & operator*(void);
    T * operator->(void) const;
    operator bool(void);

    template<typename Y>
    bool operator==(const Handle<Y> & rhs) const;
    bool operator==(T * rhs) const;
    template<typename Y>
    friend bool operator==(const Y * lhs, const Handle rhs );

    template<typename Y>
    Handle & operator=(Handle<Y> rhs);

    template<typename Y>
    Handle & TakeOwnershipOf(Handle<Y> & rhs);
    void Clear(void);

  private:
    T * m_Data;
};

Anyone knows if I am doing something incorrectly? or if the documentation is missing something?