cfmonkey的笔记本

Bitset Class

Standard C++ Library Reference 

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.

For a list of all members of this type, see bitset Members

   1:  template <size_t N>
   2:  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.

 Requirements

Header: <bitset>

> See Also

Other Resources

bitset Members
<bitset> Members

bitset Members 

Reference

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

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_ulong

Converts a bitset object to the integer 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.

 

 

 

posted on 2007-06-16 01:13 cfmonkey 阅读(285) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


导航

<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(2)

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜