# Boost.Signals: Header `<boost/signals/connection.hpp>`

## Header `<boost/signals/connection.hpp>` synopsis

    namespace boost {
      namespace signals {
        class connection;
        class scoped_connection;

        void swap(connection&, connection&);
        void swap(scoped_connection&, scoped_connection&);
      }
    }

## Class `connection` synopsis

The `connection` class represents a connection between a Signal and a Slot. It is a lightweight object that has the ability to query whether the signal and slot are currently connected, and to disconnect the signal and slot. It is always safe to query or disconnect a `connection`.

    namespace boost {
      namespace signals {
        class connection : // Class connection is LessThanComparable and EqualityComparable
          private less_than_comparable1<connection>, // Exposition only.
          private equality_comparable1<connection>// Exposition only.
        {
        public:
          connection();
          connection(const connection&);
          ~connection();

          void disconnect() const;
          bool connected() const;

          connection& operator=(const connection&);
          void swap(connection&);

          bool operator==(const connection& other) const;
          bool operator<(const connection& other) const;
        };
      }
    }

## Class `connection` members

### Constructors

`connection();`

- Effects: Sets the currently represented connection to the NULL connection.
- Postconditions: `!this->connected()`
- Throws: will not throw.

`connection(const connection& other);`

- Effects: `this` references the connection referenced by `other`.
- Throws: will not throw.

### Destructor

~`connection();`

- Effects: none.

### Connection Management

`void disconnect() const;`

- Effects: if `this->is_connected()`, disconnects the signal and slot referenced by `this`; otherwise, this operation is a no-op.
- Postconditions: `!this->is_connected()`

`bool connected() const;`

- Returns: `true` if `this` references a non-NULL connection that is still active (connected), and `false` otherwise.
- Throws: will not throw.

### Assignment and Swap

`connection& operator=(const connection& other);`

- Effects: `connection(other).swap(*this);`
- Returns: `*this`

`void swap(connection& other);`

- Effects: swaps the connections referenced in `this` and `other`.
- Throws: will not throw.

### Comparison

`bool operator==(const connection& other) const;`

- Returns: true if `this` and `other` reference the same connection or both reference the NULL connection, and `false` otherwise.
- Throws: will not throw.

`bool operator<(const connection& other) const;`

- Returns: `true` if the connection referenced by `this` precedes the connection referenced by `other` based on some implementation-defined ordering, and `false` otherwise.
- Throws: will not throw.

## Class `scoped_connection` synopsis

The `scoped_connection` class is a connection that will be automatically disconnected when the `scoped_connection` instance is destructed.

    namespace boost {
      namespace signals {
        class scoped_connection : public connection
        {
        public:
          scoped_connection();
          scoped_connection(const scoped_connection&);
          scoped_connection(const connection&);
          ~scoped_connection();

          connection& operator=(const scoped_connection&);
          connection& operator=(const connection&);
          void swap(connection&);
        };
      }
    }

## Class `scoped_connection` members

### Constructors

`scoped_connection();`

- Effects: Sets the currently represented connection to the NULL connection.
- Postconditions: `!this->connected()`
- Throws: will not throw.

`scoped_connection(const scoped_connection& other);`

- Effects: `this` references the connection referenced by `other`.
- Throws: will not throw.

`scoped_connection(const connection& other);`

- Effects: `this` references the connection referenced by `other`.
- Throws: will not throw.

### Destructor

~`connection();`

- Effects: `this->disconnect()`

### Assignment and Swap

`scoped_connection& operator=(const scoped_connection& other);`

- Effects: `scoped_connection(other).swap(*this);`
- Returns: `*this`

`scoped_connection& operator=(const connection& other);`

- Effects: `scoped_connection(other).swap(*this);`
- Returns: `*this`

`void swap(scoped_connection& other);`

- Effects: swaps the connections referenced in `this` and `other`.
- Throws: will not throw.

## Free Functions

`void swap(connection& c1, connection& c2);`

- Effects: `c1.swap(c2)`.
- Throws: will not throw.

`void swap(scoped_connection& c1, scoped_connection& c2);`

- Effects: `c1.swap(c2)`.
- Throws: will not throw.

Last modified: Fri Oct 11 05:42:05 EDT 2002