std::bitset<N>::set

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

# 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

DRApplied toBehavior as publishedCorrect behavior
LWG 186C++98the type of value was intcorrected to bool
LWG 2250C++98the behavior was undefined if pos doesnot correspond to a valid bit positionalways throws anexception in this case

# See also