##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::vector<bool>::reference

From cppreference.com
< cpp‎ | container‎ | vector bool

class reference; |  |

The std::vector<bool> specialization defines std::vector<bool>::reference as a publicly-accessible nested class. std::vector<bool>::reference proxies the behavior of references to a single bit in std::vector<bool>.

The primary use of std::vector<bool>::reference is to provide an l-value that can be returned from `operator[]`.

Any reads or writes to a vector that happen via a std::vector<bool>::reference potentially read or write to the entire underlying vector.

### [edit] Member functions

(constructor) | constructs the reference. Accessible only to std::vector<bool> itself (public member function)
(destructor) | ~reference (public member function)
operator= | assigns a bool to the referenced bit (public member function)
operator bool | returns the referenced bit (public member function) [edit]
operator ~ | returns inverted referenced bit (public member function)
flip | flips the referenced bit (public member function)

# std::vector<bool>::~reference

~reference() |  |

Destroys the reference.

# std::vector<bool>::reference::operator=

reference& operator=( bool x ); reference& operator=( const reference& x ); |  |

Assigns a value to the referenced bit.

### Parameters

x | - | value to assign

### Return value

*this

### Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

# std::vector<bool>::reference::operator bool

operator bool() const; |  |

Returns the value of the referenced bit.

### Parameters

(none)

### Return value

The referenced bit.

### Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

# std::vector<bool>::reference::operator~

bool operator~() const; |  |

Returns the inverse of the referenced bit.

### Parameters

(none)

### Return value

The inverse of the referenced bit.

### Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

# std::vector<bool>::reference::flip

reference& flip(); |  |

Inverts the referenced bit.

### Parameters

(none)

### Return value

*this

### Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

### [edit] See also

operator[] | access specified element (public member function of `std::vector`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/container/vector_bool/reference&oldid=64862"