Share via


vector<bool>::reference::flip

Inverts the Boolean value of a referenced vector<bool> element.

void flip();

Example

// vector_bool_ref_flip.cpp
// compile with: /EHsc /W4
#include <vector>
#include <iostream>

int main()
{
    using namespace std;
    vector<bool> vb = { true, false, false, true, true };

    cout << "The vector is: ";
    for (const auto& it : vb) {
        cout << it << " ";
    }
    cout << endl;

    vector<bool>::reference vbref = vb.front();
    vbref.flip();

    cout << "The vector with first element flipped is: ";
    for (const auto& it : vb) {
        cout << it << " ";
    }
    cout << endl;
}

Output

The vector is: 1 0 0 1 1
The vector with first element flipped is: 0 0 0 1 1

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector<bool>::reference Class

Standard Template Library