标准库头文件 <bitset>
来自cppreference.com
此头文件是通用工具库的一部分。
包含 | |
<string> | |
<iosfwd> | |
类 | |
实现常量长度的位数组 (类) | |
(C++11) |
std::bitset 的散列支持 (类模板特化) |
函数 | |
在 bitset 上执行二元逻辑操作 (函数) | |
执行 bitset 的流输入和输出 (函数) |
概要
#include <string> #include <iosfwd> // 对于 istream, ostream namespace std { template <size_t N> class bitset; // bitset 运算符: template <size_t N> bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; template <size_t N> bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; template <size_t N> bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; template <class charT, class traits, size_t N> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, bitset<N>& x); template <class charT, class traits, size_t N> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); // 散列支持 template <class T> struct hash; template <size_t N> struct hash<bitset<N> >; }
类 std::bitset
template<size_t N> class bitset { public: // 位引用: class reference { friend class bitset; reference() noexcept; public: ~reference() noexcept; reference& operator=(bool x) noexcept; // 针对 b[i] = x; reference& operator=(const reference&) noexcept;// 针对 b[i] = b[j]; bool operator~() const noexcept; // 翻转位 operator bool() const noexcept; // 针对 x = b[i]; reference& flip() noexcept; // 针对 b[i].flip(); }; // 构造函数: constexpr bitset() noexcept; constexpr bitset(unsigned long long val) noexcept; template<class charT, class traits, class Allocator> explicit bitset( const basic_string<charT,traits,Allocator>& str, typename basic_string<charT,traits,Allocator>::size_type pos = 0, typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos, charT zero = charT('0'), charT one = charT('1')); template <class charT> explicit bitset( const charT* str, typename basic_string<charT>::size_type n = basic_string<charT>::npos, charT zero = charT('0'), charT one = charT('1')); // bitset 操作: bitset<N>& operator&=(const bitset<N>& rhs) noexcept; bitset<N>& operator|=(const bitset<N>& rhs) noexcept; bitset<N>& operator^=(const bitset<N>& rhs) noexcept; bitset<N>& operator<<=(size_t pos) noexcept; bitset<N>& operator>>=(size_t pos) noexcept; bitset<N>& set() noexcept; bitset<N>& set(size_t pos, bool val = true); bitset<N>& reset() noexcept; bitset<N>& reset(size_t pos); bitset<N> operator~() const noexcept; bitset<N>& flip() noexcept; bitset<N>& flip(size_t pos); // 元素访问 constexpr bool operator[](size_t pos) const; // 针对 b[i]; reference operator[](size_t pos); // 针对 b[i]; unsigned long to_ulong() const; unsigned long long to_ullong() const; template <class charT = char, class traits = char_traits<charT>, class Allocator = allocator<charT> > basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; size_t count() const noexcept; constexpr size_t size() noexcept; bool operator==(const bitset<N>& rhs) const noexcept; bool operator!=(const bitset<N>& rhs) const noexcept; bool test(size_t pos) const; bool all() const noexcept; bool any() const noexcept; bool none() const noexcept; bitset<N> operator<<(size_t pos) const noexcept; bitset<N> operator>>(size_t pos) const noexcept; };