std::bitset<N>::test (3) - Linux Manuals
std::bitset<N>::test: std::bitset<N>::test
Command to display std::bitset<N>::test
manual in Linux: $ man 3 std::bitset<N>::test
NAME
std::bitset<N>::test - std::bitset<N>::test
Synopsis
bool test( size_t pos ) const;
Returns the value of the bit at the position pos.
Unlike operator[], performs a bounds check and throws std::out_of_range if pos does not correspond to a valid position in the bitset.
Parameters
pos - position of the bit to return
Return value
true if the requested bit is set, false otherwise.
Exceptions
std::out_of_range if pos does not correspond to a valid position within the bitset.
Example
// Run this code
#include <iostream>
#include <bitset>
int main()
{
std::bitset<10> b1("1111010000");
size_t idx = 0;
while (idx < b1.size() && !b1.test(idx)) {
++idx;
}
if (idx < b1.size()) {
std::cout << "first set bit at index " << idx << '\n';
} else {
std::cout << "no set bits\n";
}
}
Output:
first set bit at index 4
See also
accesses specific bit
operator[] (public member function)
Pages related to std::bitset<N>::test
- std::bitset<N>::to_string (3) - std::bitset<N>::to_string
- std::bitset<N>::to_ullong (3) - std::bitset<N>::to_ullong
- std::bitset<N>::to_ulong (3) - std::bitset<N>::to_ulong
- std::bitset<N>::all,std::bitset<N>::any,std::bitset<N>::none (3) - std::bitset<N>::all,std::bitset<N>::any,std::bitset<N>::none
- std::bitset<N>::bitset (3) - std::bitset<N>::bitset
- std::bitset<N>::count (3) - std::bitset<N>::count
- std::bitset<N>::flip (3) - std::bitset<N>::flip
- std::bitset<N>::operator&=,|=,^=,~ (3) - std::bitset<N>::operator&=,|=,^=,~
- std::bitset<N>::operator<<,<<=,>>,>>= (3) - std::bitset<N>::operator<<,<<=,>>,>>=
- std::bitset<N>::operator[] (3) - std::bitset<N>::operator[]
- std::bitset<N>::reference (3) - std::bitset<N>::reference
- std::bitset<N>::reset (3) - std::bitset<N>::reset
- std::bitset<N>::set (3) - std::bitset<N>::set
- std::bitset<N>::size (3) - std::bitset<N>::size
- std::bitset (3) - std::bitset