A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/bitset/bitset/test/ below:

public member function

<bitset>

std::bitset::test
bool test (size_t pos) const;

Return bit value

Returns whether the bit at position pos is set (i.e., whether it is one).

Unlike the access operator (operator[]), this function performs a range check on pos before retrieveing the bit value, throwing out_of_range if pos is equal or greater than the bitset size.



Parameters
pos
Order position of the bit whose value is retrieved.
Order positions are counted from the rightmost bit, which is order position 0.
size_t is an unsigned integral type.

Return valuetrue if the bit at position pos is set, and false if it is not set.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// bitset::test
#include <iostream>       // std::cout
#include <string>         // std::string
#include <cstddef>        // std::size_t
#include <bitset>         // std::bitset

int main ()
{
  std::bitset<5> foo (std::string("01011"));

  std::cout << "foo contains:\n";
  std::cout << std::boolalpha;
  for (std::size_t i=0; i<foo.size(); ++i)
    std::cout << foo.test(i) << '\n';

  return 0;
}

Output:
foo contains:
true
true
false
true
false


Data races The bitset is accessed.

Exception safetyStrong guarantee: if an exception is thrown, there are no changes in the bitset.
If pos is not a valid bit position, out_of_range is thrown.

See also
bitset::operator[]
Access bit (public member function)
bitset::count
Count bits set (public member function)
bitset::any
Test if any bit is set (public member function)
bitset::none
Test if no bit is set (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4