| Home | Libraries | People | FAQ | More

## Class template scoped_ptr

boost::interprocess::scoped_ptr

## Synopsis

    // In header: <boost/interprocess/smart_ptr/scoped_ptr.hpp>

    template<typename T, typename Deleter>
    class scoped_ptr : private Deleter {
    public:
      // types
      typedef T                    element_type;
      typedef Deleter              deleter_type;
      typedef unspecified          pointer;
      typedef pointer this_type::* unspecified_bool_type;

      // construct/copy/destruct
      explicit scoped_ptr(const pointer & = 0, const Deleter & = Deleter());
      ~scoped_ptr();

      // public member functions
      void reset(const pointer & = 0);
      void reset(const pointer &, const Deleter &);
      pointer release();
      reference operator*() const;
      pointer & operator->();
      const pointer & operator->() const;
      pointer & get();
      const pointer & get() const;
      operator unspecified_bool_type() const;
      bool operator!() const;
      void swap(scoped_ptr &);
    };

## Description

scoped_ptr stores a pointer to a dynamically allocated object. The object pointed to is guaranteed to be deleted, either on destruction of the scoped_ptr, or via an explicit reset. The user can avoid this deletion using release(). scoped_ptr is parameterized on T (the type of the object pointed to) and Deleter (the functor to be executed to delete the internal pointer). The internal pointer will be of the same pointer type as typename Deleter::pointer type (that is, if typename Deleter::pointer is offset_ptr<void>, the internal pointer will be offset_ptr<T>).

### `scoped_ptr` public construct/copy/destruct

1.     explicit scoped_ptr(const pointer & p = 0, const Deleter & d = Deleter());

   Constructs a `scoped_ptr`, storing a copy of p(which can be 0) and d. Does not throw.

2.     ~scoped_ptr();

   If the stored pointer is not 0, destroys the object pointed to by the stored pointer. calling the operator() of the stored deleter. Never throws

### `scoped_ptr` public member functions

1.     void reset(const pointer & p = 0);

   Deletes the object pointed to by the stored pointer and then stores a copy of p. Never throws

2.     void reset(const pointer & p, const Deleter & d);

   Deletes the object pointed to by the stored pointer and then stores a copy of p and a copy of d.

3.     pointer release();

   Assigns internal pointer as 0 and returns previous pointer. This will avoid deletion on destructor

4.     reference operator*() const;

   Returns a reference to the object pointed to by the stored pointer. Never throws.

5.     pointer & operator->();

   Returns the internal stored pointer. Never throws.

6.     const pointer & operator->() const;

   Returns the internal stored pointer. Never throws.

7.     pointer & get();

   Returns the stored pointer. Never throws.

8.     const pointer & get() const;

   Returns the stored pointer. Never throws.

9.     operator unspecified_bool_type() const;

   Conversion to bool Never throws

10.     bool operator!() const;

    Returns true if the stored pointer is 0. Never throws.

11.     void swap(scoped_ptr & b);

    Exchanges the internal pointer and deleter with other `scoped_ptr` Never throws.