std::bitset::operator&=,|=,^=,~

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
bitset<N>& operator&=( const bitset<N>& other );
(1)
bitset<N>& operator|=( const bitset<N>& other );
(2)
bitset<N>& operator^=( const bitset<N>& other );
(3)
bitset<N> operator~() const;
(4)

Performs binary AND, OR, XOR and NOT.

1) Sets the bits to the result of binary AND on corresponding pairs of bits of *this and other.
2) Sets the bits to the result of binary OR on corresponding pairs of bits of *this and other.
3) Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and other.
4) Returns a temporary copy of *this with all bits flipped (binary NOT).

Note that &=, |=, and ^= are only defined for bitsets of the same size N.

Contents

[edit] Parameters

other - another bitset

[edit] Return value

1-3) *this
4) bitset<N>(*this).flip()

[edit] Exceptions

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

[edit] Example

#include <iostream>
#include <string>
#include <bitset>
 
int main()
{
    std::bitset<16> dest;
    std::string pattern_str = "1001";
    std::bitset<16> pattern(pattern_str);
 
    for (size_t i = 0, ie = dest.size()/pattern_str.size(); i != ie; ++i) {
        dest <<= pattern_str.size();
        dest |= pattern;
    }
    std::cout << dest << '\n';
}

Output:

1001100110011001

[edit] See also

performs binary shift left and shift right
(public member function)