Namespaces
Variants
Views
Actions

std::bitset::all, std::bitset::any, std::bitset::none

From cppreference.com
< cpp‎ | utility‎ | bitset
Revision as of 15:15, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
bool all() const;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
bool any() const;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
bool none() const;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Checks if all, any or none of the bits are set to true.

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

Parameters

(none)

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

Example

#include <iostream>
#include <bitset>
 
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";
    std::cout << b1 << '\t' << b1.all() << '\t' << b1.any() << '\t' << b1.none() << '\n';
    std::cout << b2 << '\t' << b2.all() << '\t' << b2.any() << '\t' << b2.none() << '\n';
    std::cout << 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