Заголовочный файл стандартной библиотеки <bitset>
Материал из cppreference.com
Этот заголовочный файл является частью библиотеки основных утилит.
Включает заголовочные файлы | ||
| <string> | ||
| <iosfwd> | ||
Классы | ||
| Реализует битовый массив постоянной длины (класс) | ||
| (C++11) |
Обеспечивает поддержку хеширования для std::bitset (специализация шаблона класса) | |
Функции | ||
| выполняют побитовые операции И, ИЛИ, исключающее ИЛИ с элементами двух std::bitset (функция) | ||
| выполняют потоковый вывод/ввод для std::bitset (функция) | ||
[править] Определение
#include <string> #include <iosfwd> // для istream, ostream namespace std { template <size_t N> class bitset; // bitset operators: 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<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; };

