std::bitset::set(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

okay so bestie, we're in the C++ Standard Libary manual β€” yes, that's literally how the manual name is spelled on the page, iconic β€” and the page is std::bitset::set(3). The name line is: std::bitset::set - std::bitset::set. πŸ’–

✨ Synopsis ✨

Here's the signature tea, copied exact:

bitset& set();                                     (1) (noexcept
since C++11)
                                                             (constexpr
since C++23)
bitset& set( std::size_t pos, bool value = true ); (2) (constexpr
since C++23)

So this icon sets all bits to true or sets one bit to a specified value. πŸ’…

  1. Sets all bits to true.
  2. Sets the bit at position pos to the value value.

🌈 Parameters 🌈

  • pos β€” the position (counting from 0, i.e. from least significant to most significant) of the bit to set. 🎯
  • value β€” the value to set the bit to. 🫢

πŸ’– Return value πŸ’–

*this β€” that's the whole answer, bestie. ✨

😭 Exceptions 😭

Overload 2) throws std::out_of_range if pos does not correspond to a valid position within the bitset.

bestie, if pos is not a valid position within the bitset, overload 2) throws std::out_of_range. That is not a vibe. πŸ™ˆ

🧚 Example 🧚

// Run this code

#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';
}

🌟 Output 🌟

00000000
11111111
00000000
10101010

πŸŽ€ Defect reports πŸŽ€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. History tea, but make it C++. 🫢

  • DR: LWG 186 β€” Applied to: C++98 β€” Behavior as published: the type of value was int; Correct behavior: corrected to bool. πŸ’…

πŸ¦‹ See also πŸ¦‹

  • reset β€” sets bits to false (public member function). ⭐
  • flip β€” toggles the values of bits (public member function). πŸ”₯

okay that's the whole page, bestie! source: http://cppreference.com, version/date: 2024.06.10, and the footer is for std::bitset::set(3). mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from