NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
bitset< N > 模板类 参考

固定大小的位集 更多...

#include <bitset.hpp>

类 bitset< N > 继承关系图:
[图例]

class  reference
 位引用类,用于返回可修改的引用 更多...

Public 成员函数

constexpr bitset () noexcept
 默认构造函数,所有位初始化为0
constexpr bitset (unsigned long long value) noexcept
 整数初始化
constexpr bitset (const string_view str, const char zero='0', const char one='1')
 用字符串初始化bitset
constexpr bitset (const string &str, const char zero='0', const char one='1')
 string初始化
constexpr bitset (const char *str, const char zero='0', const char one='1')
 C风格字符串初始化
constexpr bitsetset () noexcept
 将所有位设置为1
constexpr bitsetset (const size_t pos, const bool value=true) noexcept
 将指定位置的位设置为指定值
constexpr bitsetreset () noexcept
 将所有位重置为0
constexpr bitsetreset (const size_t pos) noexcept
 将指定位置的位重置为0
constexpr bitsetflip () noexcept
 翻转所有位
constexpr bitsetflip (const size_t pos) noexcept
 翻转指定位置的位
constexpr bool operator[] (const size_t pos) const noexcept
 常量下标访问
constexpr reference operator[] (size_t pos) noexcept
 非常量下标访问
constexpr size_t size () const noexcept
 获取位数
constexpr bool empty () const noexcept
 检查是否为空
constexpr bool test (const size_t position) const noexcept
 测试指定位置的位
constexpr bitsetoperator&= (const bitset &other) noexcept
 按位与赋值
constexpr bitsetoperator|= (const bitset &other) noexcept
 按位或赋值
constexpr bitsetoperator^= (const bitset &other) noexcept
 按位异或赋值
constexpr bitset operator~ () const noexcept
 按位取反
constexpr bitsetoperator<<= (const uint32_t pos) noexcept
 左移赋值
constexpr bitsetoperator>>= (const uint32_t pos) noexcept
 右移赋值
constexpr size_t count () const noexcept
 统计值为1的位的数量
constexpr bool all () const noexcept
 检查所有位是否都为1
constexpr bool any () const noexcept
 检查是否存在值为1的位
constexpr bool none () const noexcept
 检查是否所有位都是0
constexpr unsigned long to_ulong () const
 转换为unsigned long
constexpr unsigned long long to_ullong () const
 转换为unsigned long long
constexpr bool equal_to (const bitset &other) const noexcept
 相等比较操作符
constexpr bool less_than (const bitset &other) const noexcept
 小于比较操作符(按字典序)
constexpr string to_string (const char zero, const char one) const
 转换为字符串
constexpr string to_string () const
 转换为字符串(默认使用'0'和'1')
constexpr void swap (bitset &other) noexcept
 交换两个bitset的内容
Public 成员函数 继承自 icomparable< bitset< N > >
constexpr bool operator== (const bitset< N > &rhs) const noexcept(noexcept(derived().equal_to(rhs)))
 相等比较运算符
constexpr bool operator!= (const bitset< N > &rhs) const noexcept(noexcept(!(derived().equal_to(rhs))))
 不等比较运算符
constexpr bool operator< (const bitset< N > &rhs) const noexcept(noexcept(derived().less_than(rhs)))
 小于比较运算符
constexpr bool operator> (const bitset< N > &rhs) const noexcept(noexcept(rhs.less_than(derived())))
 大于比较运算符
constexpr bool operator<= (const bitset< N > &rhs) const noexcept(noexcept(!(rhs.less_than(derived()))))
 小于等于比较运算符
constexpr bool operator>= (const bitset< N > &rhs) const noexcept(noexcept(!(derived().less_than(rhs))))
 大于等于比较运算符
Public 成员函数 继承自 ibinary< bitset< N > >
constexpr bitset< N > operator& (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator&=(other)))
 按位与运算符
constexpr bitset< N > operator| (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator|=(other)))
 按位或运算符
constexpr bitset< N > operator^ (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator^=(other)))
 按位异或运算符
constexpr bitset< N > operator~ () const noexcept(noexcept(derived().operator~()))
 按位取反运算符
constexpr bitset< N > operator<< (const uint32_t shift) const
 左移运算符
constexpr bitset< N > operator>> (const uint32_t shift) const
 右移运算符
constexpr bitset< N > & operator&= (const bitset< N > &other) noexcept(noexcept(derived().operator&=(other)))
 按位与赋值运算符
constexpr bitset< N > & operator|= (const bitset< N > &other) noexcept(noexcept(derived().operator|=(other)))
 按位或赋值运算符
constexpr bitset< N > & operator^= (const bitset< N > &other) noexcept(noexcept(derived().operator^=(other)))
 按位异或赋值运算符
constexpr bitset< N > & operator<<= (const uint32_t shift)
 左移赋值运算符
constexpr bitset< N > & operator>>= (const uint32_t shift)
 右移赋值运算符
Public 成员函数 继承自 istringify< bitset< N > >
constexpr string to_string () const
 转换为字符串

详细描述

template<size_t N>
class bitset< N >

固定大小的位集

模板参数
N位数,在编译时确定

bitset表示一个固定大小的二进制位序列,提供对每个位的独立访问 以及常见的位操作(与、或、异或、移位等)。存储效率高,操作速度快。 位数N在编译时确定,因此不能动态改变大小。

在文件 bitset.hpp35 行定义.

构造及析构函数说明

◆ bitset() [1/4]

template<size_t N>
bitset< N >::bitset ( unsigned long long value)
inlineexplicitconstexprnoexcept

整数初始化

参数
value无符号64位整数值,用于初始化低位

将二进制位复制到bitset的低位,超出N的高位被忽略。

在文件 bitset.hpp134 行定义.

◆ bitset() [2/4]

template<size_t N>
bitset< N >::bitset ( const string_view str,
const char zero = '0',
const char one = '1' )
inlineexplicitconstexpr

用字符串初始化bitset

参数
str字符串视图
zero表示0的字符,默认为'0'
one表示1的字符,默认为'1'
异常
value_exception如果字符串包含无效字符

字符串从左到右对应从高位到低位。如果字符串长度小于N,高位补0; 如果长度大于N,只使用前N个字符。

在文件 bitset.hpp162 行定义.

引用了 basic_string_view< CharT, Traits >::length(), reset() , 以及 set().

◆ bitset() [3/4]

template<size_t N>
bitset< N >::bitset ( const string & str,
const char zero = '0',
const char one = '1' )
inlineexplicitconstexpr

string初始化

参数
strstring对象
zero表示0的字符
one表示1的字符

在文件 bitset.hpp186 行定义.

引用了 bitset().

◆ bitset() [4/4]

template<size_t N>
bitset< N >::bitset ( const char * str,
const char zero = '0',
const char one = '1' )
inlineexplicitconstexpr

C风格字符串初始化

参数
strC风格字符串
zero表示0的字符
one表示1的字符

在文件 bitset.hpp195 行定义.

引用了 bitset().

成员函数说明

◆ all()

template<size_t N>
bool bitset< N >::all ( ) const
inlinenodiscardconstexprnoexcept

检查所有位是否都为1

返回
如果所有位都是1返回true

在文件 bitset.hpp441 行定义.

◆ any()

template<size_t N>
bool bitset< N >::any ( ) const
inlinenodiscardconstexprnoexcept

检查是否存在值为1的位

返回
如果至少有一个1返回true

在文件 bitset.hpp455 行定义.

被这些函数引用 none().

◆ count()

template<size_t N>
size_t bitset< N >::count ( ) const
inlinenodiscardconstexprnoexcept

统计值为1的位的数量

返回
1的位数

在文件 bitset.hpp429 行定义.

引用了 popcount().

◆ empty()

template<size_t N>
bool bitset< N >::empty ( ) const
inlinenodiscardconstexprnoexcept

检查是否为空

返回
如果N为0返回true

在文件 bitset.hpp302 行定义.

◆ equal_to()

template<size_t N>
bool bitset< N >::equal_to ( const bitset< N > & other) const
inlinenodiscardconstexprnoexcept

相等比较操作符

参数
other另一个bitset
返回
如果所有位相等返回true

在文件 bitset.hpp549 行定义.

引用了 bitset().

◆ flip() [1/2]

template<size_t N>
bitset & bitset< N >::flip ( )
inlineconstexprnoexcept

翻转所有位

返回
自身引用

在文件 bitset.hpp254 行定义.

引用了 bitset().

被这些函数引用 operator~().

◆ flip() [2/2]

template<size_t N>
bitset & bitset< N >::flip ( const size_t pos)
inlineconstexprnoexcept

翻转指定位置的位

参数
pos位位置
返回
自身引用

在文件 bitset.hpp267 行定义.

引用了 bitset().

◆ less_than()

template<size_t N>
bool bitset< N >::less_than ( const bitset< N > & other) const
inlinenodiscardconstexprnoexcept

小于比较操作符(按字典序)

参数
other另一个bitset
返回
比较结果

在文件 bitset.hpp556 行定义.

引用了 bitset().

◆ none()

template<size_t N>
bool bitset< N >::none ( ) const
inlinenodiscardconstexprnoexcept

检查是否所有位都是0

返回
如果没有1返回true

在文件 bitset.hpp468 行定义.

引用了 any().

◆ operator&=()

template<size_t N>
bitset & bitset< N >::operator&= ( const bitset< N > & other)
inlineconstexprnoexcept

按位与赋值

参数
other另一个bitset
返回
自身引用

在文件 bitset.hpp321 行定义.

引用了 bitset().

◆ operator<<=()

template<size_t N>
bitset & bitset< N >::operator<<= ( const uint32_t pos)
inlineconstexprnoexcept

左移赋值

参数
pos左移位数
返回
自身引用

在文件 bitset.hpp367 行定义.

引用了 bitset() , 以及 reset().

◆ operator>>=()

template<size_t N>
bitset & bitset< N >::operator>>= ( const uint32_t pos)
inlineconstexprnoexcept

右移赋值

参数
pos右移位数
返回
自身引用

在文件 bitset.hpp399 行定义.

引用了 bitset() , 以及 reset().

◆ operator[]() [1/2]

template<size_t N>
bool bitset< N >::operator[] ( const size_t pos) const
inlinenodiscardconstexprnoexcept

常量下标访问

参数
pos位位置
返回
该位的bool值

在文件 bitset.hpp280 行定义.

引用了 test().

◆ operator[]() [2/2]

template<size_t N>
reference bitset< N >::operator[] ( size_t pos)
inlinenodiscardconstexprnoexcept

非常量下标访问

参数
pos位位置
返回
位引用对象,可用于修改

在文件 bitset.hpp287 行定义.

◆ operator^=()

template<size_t N>
bitset & bitset< N >::operator^= ( const bitset< N > & other)
inlineconstexprnoexcept

按位异或赋值

参数
other另一个bitset
返回
自身引用

在文件 bitset.hpp345 行定义.

引用了 bitset().

◆ operator|=()

template<size_t N>
bitset & bitset< N >::operator|= ( const bitset< N > & other)
inlineconstexprnoexcept

按位或赋值

参数
other另一个bitset
返回
自身引用

在文件 bitset.hpp333 行定义.

引用了 bitset().

◆ operator~()

template<size_t N>
bitset bitset< N >::operator~ ( ) const
inlinenodiscardconstexprnoexcept

按位取反

返回
取反后的新bitset

在文件 bitset.hpp356 行定义.

引用了 bitset() , 以及 flip().

◆ reset() [1/2]

template<size_t N>
bitset & bitset< N >::reset ( )
inlineconstexprnoexcept

将所有位重置为0

返回
自身引用

在文件 bitset.hpp232 行定义.

引用了 bitset().

被这些函数引用 bitset(), operator<<=() , 以及 operator>>=().

◆ reset() [2/2]

template<size_t N>
bitset & bitset< N >::reset ( const size_t pos)
inlineconstexprnoexcept

将指定位置的位重置为0

参数
pos位位置
返回
自身引用

在文件 bitset.hpp242 行定义.

引用了 bitset().

◆ set() [1/2]

template<size_t N>
bitset & bitset< N >::set ( )
inlineconstexprnoexcept

将所有位设置为1

返回
自身引用

在文件 bitset.hpp202 行定义.

引用了 bitset().

被这些函数引用 bitset() , 以及 bitset< N >::reference::reference().

◆ set() [2/2]

template<size_t N>
bitset & bitset< N >::set ( const size_t pos,
const bool value = true )
inlineconstexprnoexcept

将指定位置的位设置为指定值

参数
pos位位置
value要设置的值,默认为true
返回
自身引用

在文件 bitset.hpp216 行定义.

引用了 bitset().

◆ size()

template<size_t N>
size_t bitset< N >::size ( ) const
inlinenodiscardconstexprnoexcept

获取位数

返回
模板参数N

在文件 bitset.hpp296 行定义.

◆ swap()

template<size_t N>
void bitset< N >::swap ( bitset< N > & other)
inlineconstexprnoexcept

交换两个bitset的内容

参数
other另一个bitset

在文件 bitset.hpp583 行定义.

引用了 bitset().

◆ test()

template<size_t N>
bool bitset< N >::test ( const size_t position) const
inlinenodiscardconstexprnoexcept

测试指定位置的位

参数
position位位置
返回
位的值

在文件 bitset.hpp309 行定义.

被这些函数引用 operator[]() , 以及 to_string().

◆ to_string() [1/2]

template<size_t N>
string bitset< N >::to_string ( ) const
inlinenodiscardconstexpr

转换为字符串(默认使用'0'和'1')

返回
字符串表示

在文件 bitset.hpp577 行定义.

引用了 to_string().

被这些函数引用 to_string().

◆ to_string() [2/2]

template<size_t N>
string bitset< N >::to_string ( const char zero,
const char one ) const
inlinenodiscardconstexpr

转换为字符串

参数
zero表示0的字符
one表示1的字符
返回
字符串表示,高位在左

在文件 bitset.hpp564 行定义.

引用了 basic_string< CharT, Traits, Alloc >::push_back(), basic_string< CharT, Traits, Alloc >::reserve() , 以及 test().

◆ to_ullong()

template<size_t N>
unsigned long long bitset< N >::to_ullong ( ) const
inlinenodiscardconstexpr

转换为unsigned long long

返回
unsigned long long表示的位值
异常
value_exception如果值超出unsigned long long范围

在文件 bitset.hpp514 行定义.

◆ to_ulong()

template<size_t N>
unsigned long bitset< N >::to_ulong ( ) const
inlinenodiscardconstexpr

转换为unsigned long

返回
unsigned long表示的位值
异常
value_exception如果值超出unsigned long范围

在文件 bitset.hpp475 行定义.


该类的文档由以下文件生成: