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 (const block_type 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
 翻转指定位置的位
NEFORCE_NODISCARD constexpr bool operator[] (const size_t pos) const noexcept
 常量下标访问
NEFORCE_NODISCARD constexpr reference operator[] (size_t pos) noexcept
 非常量下标访问
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr size_t size () const noexcept
 获取位数
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr bool empty () const noexcept
 检查是否为空
NEFORCE_NODISCARD constexpr bool test (const size_t position) const noexcept
 测试指定位置的位
NEFORCE_NODISCARD constexpr bitsetoperator&= (const bitset &other) noexcept
 按位与赋值
NEFORCE_NODISCARD constexpr bitsetoperator|= (const bitset &other) noexcept
 按位或赋值
NEFORCE_NODISCARD constexpr bitsetoperator^= (const bitset &other) noexcept
 按位异或赋值
NEFORCE_NODISCARD constexpr bitset operator~ () const noexcept
 按位取反
NEFORCE_NODISCARD constexpr bitsetoperator<<= (const uint32_t pos) noexcept
 左移赋值
NEFORCE_NODISCARD constexpr bitsetoperator>>= (const uint32_t pos) noexcept
 右移赋值
NEFORCE_NODISCARD constexpr size_t count () const noexcept
 统计值为1的位的数量
NEFORCE_NODISCARD constexpr bool all () const noexcept
 检查所有位是否都为1
NEFORCE_NODISCARD constexpr bool any () const noexcept
 检查是否存在值为1的位
NEFORCE_NODISCARD constexpr bool none () const noexcept
 检查是否所有位都是0
NEFORCE_NODISCARD constexpr unsigned long to_ulong () const noexcept
 转换为unsigned long
NEFORCE_NODISCARD constexpr unsigned long long to_ullong () const noexcept
 转换为unsigned long long
NEFORCE_NODISCARD constexpr bool operator== (const bitset &other) const noexcept
 相等比较操作符
NEFORCE_NODISCARD constexpr bool operator< (const bitset &other) const noexcept
 小于比较操作符(按字典序)
NEFORCE_NODISCARD constexpr size_t to_hash () const noexcept
 计算哈希值
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string (const char zero, const char one) const
 转换为字符串
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string () const
 转换为字符串(默认使用'0'和'1')
constexpr void swap (bitset &other) noexcept
 交换两个bitset的内容
Public 成员函数 继承自 icomparable< bitset< N > >
NEFORCE_NODISCARD constexpr bool operator== (const bitset< N > &rhs) const noexcept(noexcept(derived()==rhs))
 相等比较运算符
NEFORCE_NODISCARD constexpr bool operator!= (const bitset< N > &rhs) const noexcept(noexcept(!(*this==rhs)))
 不等比较运算符
NEFORCE_NODISCARD constexpr bool operator< (const bitset< N > &rhs) const noexcept(noexcept(derived()< rhs))
 小于比较运算符
NEFORCE_NODISCARD constexpr bool operator> (const bitset< N > &rhs) const noexcept(noexcept(rhs< derived()))
 大于比较运算符
NEFORCE_NODISCARD constexpr bool operator<= (const bitset< N > &rhs) const noexcept(noexcept(!(derived() > rhs)))
 小于等于比较运算符
NEFORCE_NODISCARD constexpr bool operator>= (const bitset< N > &rhs) const noexcept(noexcept(!(derived()< rhs)))
 大于等于比较运算符
Public 成员函数 继承自 ihashable< bitset< N > >
NEFORCE_NODISCARD constexpr size_t to_hash () const noexcept(noexcept(derived().to_hash()))
 获取对象的哈希值
Public 成员函数 继承自 ibinary< bitset< N > >
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator& (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator&=(other)))
 按位与运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator| (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator|=(other)))
 按位或运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator^ (const bitset< N > &other) const noexcept(noexcept(const_cast< bitset< N > & >(derived()).operator^=(other)))
 按位异或运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator~ () const noexcept(noexcept(derived().operator~()))
 按位取反运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator<< (const uint32_t shift) const
 左移运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR14 bitset< N > operator>> (const uint32_t shift) const
 右移运算符
NEFORCE_CONSTEXPR14 bitset< N > & operator&= (const bitset< N > &other) noexcept(noexcept(derived().operator&=(other)))
 按位与赋值运算符
NEFORCE_CONSTEXPR14 bitset< N > & operator|= (const bitset< N > &other) noexcept(noexcept(derived().operator|=(other)))
 按位或赋值运算符
NEFORCE_CONSTEXPR14 bitset< N > & operator^= (const bitset< N > &other) noexcept(noexcept(derived().operator^=(other)))
 按位异或赋值运算符
NEFORCE_CONSTEXPR14 bitset< N > & operator<<= (const uint32_t shift)
 左移赋值运算符
NEFORCE_CONSTEXPR14 bitset< N > & operator>>= (const uint32_t shift)
 右移赋值运算符
Public 成员函数 继承自 istringify< bitset< N > >
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string () const
 转换为字符串

详细描述

template<size_t N>
class bitset< N >

固定大小的位集

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

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

在文件 bitset.hpp34 行定义.

构造及析构函数说明

◆ bitset() [1/4]

template<size_t N>
bitset< N >::bitset ( const block_type value)
inlineexplicitconstexprnoexcept

整数初始化

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

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

在文件 bitset.hpp126 行定义.

◆ 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.hpp141 行定义.

引用了 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.hpp165 行定义.

引用了 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.hpp174 行定义.

引用了 bitset().

成员函数说明

◆ all()

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::all ( ) const
inlineconstexprnoexcept

检查所有位是否都为1

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

在文件 bitset.hpp420 行定义.

◆ any()

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::any ( ) const
inlineconstexprnoexcept

检查是否存在值为1的位

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

在文件 bitset.hpp433 行定义.

被这些函数引用 none().

◆ count()

template<size_t N>
NEFORCE_NODISCARD constexpr size_t bitset< N >::count ( ) const
inlineconstexprnoexcept

统计值为1的位的数量

返回
1的位数

在文件 bitset.hpp408 行定义.

引用了 popcount().

◆ empty()

template<size_t N>
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr bool bitset< N >::empty ( ) const
inlineconstexprnoexcept

检查是否为空

返回
如果N为0返回true

在文件 bitset.hpp281 行定义.

◆ flip() [1/2]

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

翻转所有位

返回
自身引用

在文件 bitset.hpp233 行定义.

引用了 bitset().

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

◆ flip() [2/2]

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

翻转指定位置的位

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

在文件 bitset.hpp246 行定义.

引用了 bitset().

◆ none()

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::none ( ) const
inlineconstexprnoexcept

检查是否所有位都是0

返回
如果没有1返回true

在文件 bitset.hpp446 行定义.

引用了 any().

◆ operator&=()

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

按位与赋值

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

在文件 bitset.hpp300 行定义.

引用了 bitset().

◆ operator<()

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::operator< ( const bitset< N > & other) const
inlineconstexprnoexcept

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

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

在文件 bitset.hpp538 行定义.

引用了 bitset().

◆ operator<<=()

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

左移赋值

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

在文件 bitset.hpp346 行定义.

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

◆ operator==()

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

相等比较操作符

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

在文件 bitset.hpp531 行定义.

引用了 bitset().

◆ operator>>=()

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

右移赋值

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

在文件 bitset.hpp378 行定义.

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

◆ operator[]() [1/2]

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::operator[] ( const size_t pos) const
inlineconstexprnoexcept

常量下标访问

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

在文件 bitset.hpp259 行定义.

引用了 test().

◆ operator[]() [2/2]

template<size_t N>
NEFORCE_NODISCARD constexpr reference bitset< N >::operator[] ( size_t pos)
inlineconstexprnoexcept

非常量下标访问

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

在文件 bitset.hpp266 行定义.

◆ operator^=()

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

按位异或赋值

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

在文件 bitset.hpp324 行定义.

引用了 bitset().

◆ operator|=()

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

按位或赋值

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

在文件 bitset.hpp312 行定义.

引用了 bitset().

◆ operator~()

template<size_t N>
NEFORCE_NODISCARD constexpr bitset bitset< N >::operator~ ( ) const
inlineconstexprnoexcept

按位取反

返回
取反后的新bitset

在文件 bitset.hpp335 行定义.

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

◆ reset() [1/2]

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

将所有位重置为0

返回
自身引用

在文件 bitset.hpp211 行定义.

引用了 bitset().

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

◆ reset() [2/2]

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

将指定位置的位重置为0

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

在文件 bitset.hpp221 行定义.

引用了 bitset().

◆ set() [1/2]

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

将所有位设置为1

返回
自身引用

在文件 bitset.hpp181 行定义.

引用了 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.hpp195 行定义.

引用了 bitset().

◆ size()

template<size_t N>
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr size_t bitset< N >::size ( ) const
inlineconstexprnoexcept

获取位数

返回
模板参数N

在文件 bitset.hpp275 行定义.

◆ swap()

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

交换两个bitset的内容

参数
other另一个bitset

在文件 bitset.hpp571 行定义.

引用了 bitset().

◆ test()

template<size_t N>
NEFORCE_NODISCARD constexpr bool bitset< N >::test ( const size_t position) const
inlineconstexprnoexcept

测试指定位置的位

参数
position位位置
返回
位的值

在文件 bitset.hpp288 行定义.

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

◆ to_hash()

template<size_t N>
NEFORCE_NODISCARD constexpr size_t bitset< N >::to_hash ( ) const
inlineconstexprnoexcept

计算哈希值

返回
哈希值

在文件 bitset.hpp544 行定义.

◆ to_string() [1/2]

template<size_t N>
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string bitset< N >::to_string ( ) const
inline

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

返回
字符串表示

在文件 bitset.hpp565 行定义.

引用了 to_string().

被这些函数引用 to_string().

◆ to_string() [2/2]

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

转换为字符串

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

在文件 bitset.hpp552 行定义.

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

◆ to_ullong()

template<size_t N>
NEFORCE_NODISCARD constexpr unsigned long long bitset< N >::to_ullong ( ) const
inlineconstexprnoexcept

转换为unsigned long long

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

在文件 bitset.hpp492 行定义.

◆ to_ulong()

template<size_t N>
NEFORCE_NODISCARD constexpr unsigned long bitset< N >::to_ulong ( ) const
inlineconstexprnoexcept

转换为unsigned long

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

在文件 bitset.hpp453 行定义.


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