std::bitset<N>::set
Min standard notice:
Sets all bits to true or sets one bit to specified value.
# Declarations
bitset& set();
(noexcept since C++11) (constexpr since C++23)
bitset& set( std::size_t pos, bool value = true );
(constexpr since C++23)
# Parameters
pos: the position (counting from 0, i.e. from least significant to most significant) of the bit to setvalue: the value to set the bit to
# Return value
*this
# Example
#include <bitset>
#include <cstddef>
#include <iostream>
int main()
{
std::bitset<8> b;
std::cout << b << '\n';
std::cout << b.set() << '\n';
std::cout << b.reset() << '\n';
for (std::size_t i = 1; i < b.size(); i += 2)
b.set(i);
std::cout << b << '\n';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 186 | C++98 | the type of value was int | corrected to bool |
| LWG 2250 | C++98 | the behavior was undefined if pos doesnot correspond to a valid bit position | always throws anexception in this case |