| Home | Libraries | People | FAQ | More

## Class scoped_connection

boost::signals2::scoped_connection — Limits a signal-slot connection lifetime to a particular scope.

## Synopsis

    // In header: <boost/signals2/connection.hpp>

    class scoped_connection : public connection {
    public:
      // construct/copy/destruct
      scoped_connection();
      scoped_connection(const connection&);
      scoped_connection(scoped_connection&&);
      scoped_connection(connection&&);
      scoped_connection& operator=(const connection&);
      scoped_connection& operator=(scoped_connection&&);
      scoped_connection& operator=(connection&&);
      ~scoped_connection();

      // public methods
      connection release();
    private:
      // construct/copy/destruct
      scoped_connection(const scoped_connection&);
      scoped_connection& operator=(const scoped_connection&);
    };

## Description

A connection which automatically disconnects on destruction.

###### Thread Safety

The methods of the `scoped_connection` class (including those inherited from its base `connection` class) are thread-safe with the exception of signals2::connection::swap, release, and the assignment operator. A `scoped_connection` object should not be accessed concurrently when any of these operations is in progress. However, it is always safe to access a different `connection` object in another thread, even if it references the same underlying signal-slot connection.

### `scoped_connection` public construct/copy/destruct

1.     scoped_connection();

   Default constructs an empty scoped_connection.

   Postconditions: | `connected() == false`
   Throws: | Will not throw.

2.     scoped_connection(const connection& other);

   Effects: | `this` references the connection referenced by `other`.
   Postconditions: | `connected() == other.connected()`
   Throws: | Will not throw.

3.     scoped_connection(scoped_connection&& other);

   Move constructor.

   Effects: | `this` references the connection formerly referenced by `other`. The moved-from `other` no longer references any connection.
   Throws: | Will not throw.

4.     scoped_connection(connection&& other);

   Move constructor.

   Effects: | `this` references the connection formerly referenced by `other`. The moved-from `other` no longer references any connection.
   Throws: | Will not throw.

5.     scoped_connection& operator=(const connection& rhs);

   Copy assignment from unscoped connection.

   Effects: | `this` references the connection referenced by `rhs`. If `this` already references another connection, the old connection will be disconnected first.
   Postconditions: | `connected() == other.connected()`
   Throws: | Will not throw.

6.     scoped_connection& operator=(scoped_connection&& rhs);

   Move assignment.

   Effects: | `this` references the connection formerly referenced by `rhs`. The moved-from `rhs` no longer references any connection. If `this` already references another connection, the old connection will be disconnected first.
   Throws: | Will not throw.

7.     scoped_connection& operator=(connection&& rhs);

   Move assignment.

   Effects: | `this` references the connection formerly referenced by `rhs`. The moved-from `rhs` no longer references any connection. If `this` already references another connection, the old connection will be disconnected first.
   Throws: | Will not throw.

8.     ~scoped_connection();

   Effects: | If `this->connected()`, disconnects the signal-slot connection.

### `scoped_connection` public methods

1.     connection release();

   Effects: | Releases the connection so it will not be disconnected by the `scoped_connection` when it is destroyed or reassigned. The `scoped_connection` is reset to the NULL connection after this call completes.
   Postconditions: | `connected() == false`
   Returns: | A connection object referencing the connection which was released by the `scoped_connection`.

### `scoped_connection` private construct/copy/destruct

1.     scoped_connection(const scoped_connection& other);

   The scoped_connection class is not copyable. It may only be copy constructed from an unscoped `connection` object.

2.     scoped_connection& operator=(const scoped_connection& rhs);

   The scoped_connection class is not copyable. It may only be copy assigned from an unscoped `connection` object.