std::bitset::set(3)
πΈ 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. π
- Sets all bits to
true. - Sets the bit at position
posto the valuevalue.
π Parameters π
posβ the position (counting from0, 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, ifposis not a valid position within the bitset, overload2)throwsstd::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 ofvaluewasint; Correct behavior: corrected tobool. π
π¦ See also π¦
resetβ sets bits tofalse(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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms