std::bitset...bitset::none(3)

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

πŸ’… std::bitset::all, std::bitset::any, std::bitset::none

okay bestie, so this is straight out of the C++ Standard Library (the manual page std::bitset...bitset::none(3)), and it's literally just three little bestie functions that vibe-check your bitset for you. No cap.


πŸ¦‹ Synopsis

bool all() const;  (1) (noexcept since C++11)
                       (constexpr since C++23)
bool any() const;  (2) (noexcept since C++11)
                       (constexpr since C++23)
bool none() const; (3) (noexcept since C++11)
                       (constexpr since C++23)

So what's the tea on each one? πŸ«–

  1. Checks if all bits are set to true.
  2. Checks if any bits are set to true.
  3. Checks if none of the bits are set to true.

that's it. that's the whole personality. three iconique little yes/no questions πŸ’…


πŸŽ€ Parameters

(none) β€” literally nothing, she takes no arguments, she doesn't need them, she's booked and busy 🌸


✨ Return value

  1. true if all bits are set to true, otherwise false.
  2. true if any of the bits are set to true, otherwise false.
  3. true if none of the bits are set to true, otherwise false.

like... the range is giving bool. no surprises here, bestie, she's consistent πŸ‘‘


πŸ”₯ Example

go ahead and run this code, i'll wait πŸ“

#include <bitset>
#include <iostream>

int main()
{
    std::bitset<4> b1("0000");
    std::bitset<4> b2("0101");
    std::bitset<4> b3("1111");

    std::cout
        << "bitset\t" << "all\t" << "any\t" << "none\n"
        << b1 << '\t' << b1.all() << '\t' << b1.any() << '\t' << b1.none() << '\n'
        << b2 << '\t' << b2.all() << '\t' << b2.any() << '\t' << b2.none() << '\n'
        << b3 << '\t' << b3.all() << '\t' << b3.any() << '\t' << b3.none() << '\n';
}

Output:

bitset  all any none
0000    0   0   1
0101    0   1   0
1111    1   1   0

the way 0000 is like "i am nothing" and 1111 is like "i AM the moment" πŸ˜­πŸ’€


πŸ’€ Defect reports

so sometimes the standards committee had to go back and fix stuff retroactively, and these are the receipts πŸ‘€ The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • LWG 693 β€” Applied to: C++98 β€” Behavior as published: the member function all() was not provided β€” Correct behavior: provided

yeah, all() literally didn't exist in C++98 and then it did. character development fr fr 🧚


πŸ’œ See also

  • count β€” returns the number of bits set to true (public member function)
  • popcount (C++20) β€” counts the number of 1 bits in an unsigned integer (function template)

and that's the whole page, bestie 🫢

source: http://cppreference.com Β· version 2024.06.10 Β· page std::bitset...bitset::none(3) β€” ok go check your bits, ily, bye πŸ’–βœ¨πŸŒ·

πŸ“¦ where this page comes from