bitset容器
是一个位容器
template<size_t _N>
class bitset
{
public:
typedef unsigned long _Ty;
private:
enum {_Nb=CHARA_BIT*sizeof(_Ty), _Nw=(_N-1)/_Nb};
_Ty _A[_Nw+1];
}
空间分配
如果小于4个字节,就分配4个字节,通过一个_A数组来决定。
检测位
bool test(size_t _P) const
{
if(_N<=_P)
_Xran();
return ((_A[_P/_Nb]&((_Ty)1<<_P%_Nb))!=0);
}
检测_P的位置是0,还是1
输出
friend ostream& operator<<(ostream& _O, bitset<_N>& _R){
for(int i=_N;_P>0;)
_O<<(_R.test(--_P)?'1':'0';
return _O;
}