次の方法で共有


bitset Class

Describes a type of object that stores a sequence consisting of a fixed number of bits that provide a compact way of keeping flags for a set of items or conditions. The bitset class supports operations on objects of type bitset that contain a collection of bits and provide constant-time access to each bit.

template <size_t N> 
   class bitset

Parameters

  • N
    Specifies the number of bits in the bitset object with a nonzero integer of type size_t that must be known at compile time.

Remarks

Unlike the similar vector<bool> Class, the bitset class does not have iterators and is not an Standard Template Library container. It also differs from vector<bool> by being of some specific size that is fixed at compile time in accordance with the size specified by the template parameter N when the bitset<N> is declared.

A bit is set if its value is 1 and reset if its value is 0. To flip or toggle a bit is to change its value from 1 to 0 or from 0 to 1. The N bits in a bitset are indexed by integer values from 0 to N - 1, where 0 indexes the first bit position and N* *- 1 the final bit position.

Constructors

bitset

Constructs an object of class bitset<N> and initializes the bits to zero, to some specified value, or to values obtained from characters in a string.

Typedefs

element_type

A type that is a synonym for the data type bool and can be used to reference element bits in a bitset.

Member Functions

all

Tests all of the bits in this bitset to determine whether they are all set to true.

any

The member function tests whether any bit in the sequence is set to 1.

count

The member function returns the number of bits set in the bit sequence.

flip

Toggles the value of all the bits in a bitset or toggles a single bit at a specified position.

none

Tests if no bit has been set to 1 in a bitset object.

reset

Resets all the bits in a bitset to 0 or resets a bit at a specified position to 0.

set

Sets all the bits in a bitset to 1 or sets a bit at a specified position to 1.

size

Returns the number of bits in a bitset object.

test

Tests whether the bit at a specified position in a bitset is set to 1.

to_string

Converts a bitset object to a string representation.

to_ullong

Returns the sum of the bit values in the bitset as an unsigned long long.

to_ulong

Converts a bitset object to the unsigned long that would generate the sequence of bits contained if used to initialize the bitset.

Member Classes

reference

A proxy class that provides references to bits contained in a bitset that is used to access and manipulate the individual bits as a helper class for the operator[] of class bitset.

Operators

operator!=

Tests a target bitset for inequality with a specified bitset.

operator&=

Performs a bitwise combination of bitsets with the logical AND operation.

operator<<

Shifts the bits in a bitset to the left a specified number of positions and returns the result to a new bitset.

operator<<=

Shifts the bits in a bitset to the left a specified number of positions and returns the result to the targeted bitset.

operator==

Tests a target bitset for equality with a specified bitset.

operator>>

Shifts the bits in a bitset to the right a specified number of positions and returns the result to a new bitset.

operator>>=

Shifts the bits in a bitset to the right a specified number of positions and returns the result to the targeted bitset.

operator[]

Returns a reference to a bit at a specified position in a bitset if the bitset is modifiable; otherwise, it returns the value of the bit at that position.

operator^=

Performs a bitwise combination of bitsets with the exclusive OR operation.

operator|=

Performs a bitwise combination of bitsets with the inclusive OR operation.

operator~

Toggles all the bits in a target bitset and returns the result.

Requirements

Header: <bitset>

Namespace: std