10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_BITSET 110b57cec5SDimitry Andric#define _LIBCPP_BITSET 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric bitset synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andricnamespace std { 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <size_t N> 220b57cec5SDimitry Andricclass bitset 230b57cec5SDimitry Andric{ 240b57cec5SDimitry Andricpublic: 250b57cec5SDimitry Andric // bit reference: 260b57cec5SDimitry Andric class reference 270b57cec5SDimitry Andric { 280b57cec5SDimitry Andric friend class bitset; 290b57cec5SDimitry Andric reference() noexcept; 300b57cec5SDimitry Andric public: 310b57cec5SDimitry Andric ~reference() noexcept; 320b57cec5SDimitry Andric reference& operator=(bool x) noexcept; // for b[i] = x; 330b57cec5SDimitry Andric reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 340b57cec5SDimitry Andric bool operator~() const noexcept; // flips the bit 350b57cec5SDimitry Andric operator bool() const noexcept; // for x = b[i]; 360b57cec5SDimitry Andric reference& flip() noexcept; // for b[i].flip(); 370b57cec5SDimitry Andric }; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric // 23.3.5.1 constructors: 400b57cec5SDimitry Andric constexpr bitset() noexcept; 410b57cec5SDimitry Andric constexpr bitset(unsigned long long val) noexcept; 420b57cec5SDimitry Andric template <class charT> 430b57cec5SDimitry Andric explicit bitset(const charT* str, 440b57cec5SDimitry Andric typename basic_string<charT>::size_type n = basic_string<charT>::npos, 450b57cec5SDimitry Andric charT zero = charT('0'), charT one = charT('1')); 460b57cec5SDimitry Andric template<class charT, class traits, class Allocator> 470b57cec5SDimitry Andric explicit bitset(const basic_string<charT,traits,Allocator>& str, 480b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type pos = 0, 490b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type n = 500b57cec5SDimitry Andric basic_string<charT,traits,Allocator>::npos, 510b57cec5SDimitry Andric charT zero = charT('0'), charT one = charT('1')); 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 540b57cec5SDimitry Andric bitset& operator&=(const bitset& rhs) noexcept; 550b57cec5SDimitry Andric bitset& operator|=(const bitset& rhs) noexcept; 560b57cec5SDimitry Andric bitset& operator^=(const bitset& rhs) noexcept; 570b57cec5SDimitry Andric bitset& operator<<=(size_t pos) noexcept; 580b57cec5SDimitry Andric bitset& operator>>=(size_t pos) noexcept; 590b57cec5SDimitry Andric bitset& set() noexcept; 600b57cec5SDimitry Andric bitset& set(size_t pos, bool val = true); 610b57cec5SDimitry Andric bitset& reset() noexcept; 620b57cec5SDimitry Andric bitset& reset(size_t pos); 630b57cec5SDimitry Andric bitset operator~() const noexcept; 640b57cec5SDimitry Andric bitset& flip() noexcept; 650b57cec5SDimitry Andric bitset& flip(size_t pos); 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric // element access: 680b57cec5SDimitry Andric constexpr bool operator[](size_t pos) const; // for b[i]; 690b57cec5SDimitry Andric reference operator[](size_t pos); // for b[i]; 700b57cec5SDimitry Andric unsigned long to_ulong() const; 710b57cec5SDimitry Andric unsigned long long to_ullong() const; 720b57cec5SDimitry Andric template <class charT, class traits, class Allocator> 730b57cec5SDimitry Andric basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 740b57cec5SDimitry Andric template <class charT, class traits> 750b57cec5SDimitry Andric basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 760b57cec5SDimitry Andric template <class charT> 770b57cec5SDimitry Andric basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 780b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; 790b57cec5SDimitry Andric size_t count() const noexcept; 800b57cec5SDimitry Andric constexpr size_t size() const noexcept; 810b57cec5SDimitry Andric bool operator==(const bitset& rhs) const noexcept; 820b57cec5SDimitry Andric bool operator!=(const bitset& rhs) const noexcept; 830b57cec5SDimitry Andric bool test(size_t pos) const; 840b57cec5SDimitry Andric bool all() const noexcept; 850b57cec5SDimitry Andric bool any() const noexcept; 860b57cec5SDimitry Andric bool none() const noexcept; 870b57cec5SDimitry Andric bitset operator<<(size_t pos) const noexcept; 880b57cec5SDimitry Andric bitset operator>>(size_t pos) const noexcept; 890b57cec5SDimitry Andric}; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric// 23.3.5.3 bitset operators: 920b57cec5SDimitry Andrictemplate <size_t N> 930b57cec5SDimitry Andricbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andrictemplate <size_t N> 960b57cec5SDimitry Andricbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andrictemplate <size_t N> 990b57cec5SDimitry Andricbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1020b57cec5SDimitry Andricbasic_istream<charT, traits>& 1030b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1060b57cec5SDimitry Andricbasic_ostream<charT, traits>& 1070b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andrictemplate <size_t N> struct hash<std::bitset<N>>; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric} // std 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric*/ 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric#include <__bit_reference> 116*04eeddc0SDimitry Andric#include <__config> 1170b57cec5SDimitry Andric#include <__functional_base> 118fe6060f1SDimitry Andric#include <climits> 119fe6060f1SDimitry Andric#include <cstddef> 120fe6060f1SDimitry Andric#include <iosfwd> 121fe6060f1SDimitry Andric#include <stdexcept> 122fe6060f1SDimitry Andric#include <string> 123*04eeddc0SDimitry Andric#include <version> 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1260b57cec5SDimitry Andric#pragma GCC system_header 1270b57cec5SDimitry Andric#endif 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1300b57cec5SDimitry Andric#include <__undef_macros> 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1360b57cec5SDimitry Andricclass __bitset; 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1390b57cec5SDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > 1400b57cec5SDimitry Andric{ 1410b57cec5SDimitry Andric static const bool value = true; 1420b57cec5SDimitry Andric}; 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1450b57cec5SDimitry Andricclass __bitset 1460b57cec5SDimitry Andric{ 1470b57cec5SDimitry Andricpublic: 1480b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 1490b57cec5SDimitry Andric typedef size_t size_type; 1500b57cec5SDimitry Andric typedef size_type __storage_type; 1510b57cec5SDimitry Andricprotected: 1520b57cec5SDimitry Andric typedef __bitset __self; 1530b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 1540b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 1550b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 1560b57cec5SDimitry Andric 1570b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 1580b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 1590b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 1600b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 1610b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric __storage_type __first_[_N_words]; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 1660b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 1670b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 1680b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1710b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 1720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1730b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 1760b57cec5SDimitry Andric {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 1770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 1780b57cec5SDimitry Andric {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 1790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 1800b57cec5SDimitry Andric {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 1810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 1820b57cec5SDimitry Andric {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1850b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 1860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1870b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 1880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1890b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric void flip() _NOEXCEPT; 1920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const 1930b57cec5SDimitry Andric {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 1940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const 1950b57cec5SDimitry Andric {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric bool all() const _NOEXCEPT; 1980b57cec5SDimitry Andric bool any() const _NOEXCEPT; 1990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2000b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 2010b57cec5SDimitry Andricprivate: 2020b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2030b57cec5SDimitry Andric void __init(unsigned long long __v, false_type) _NOEXCEPT; 2040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2050b57cec5SDimitry Andric void __init(unsigned long long __v, true_type) _NOEXCEPT; 2060b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2070b57cec5SDimitry Andric unsigned long to_ulong(false_type) const; 2080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2090b57cec5SDimitry Andric unsigned long to_ulong(true_type) const; 2100b57cec5SDimitry Andric unsigned long long to_ullong(false_type) const; 2110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2120b57cec5SDimitry Andric unsigned long long to_ullong(true_type) const; 2130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2140b57cec5SDimitry Andric unsigned long long to_ullong(true_type, false_type) const; 2150b57cec5SDimitry Andric unsigned long long to_ullong(true_type, true_type) const; 2160b57cec5SDimitry Andric}; 2170b57cec5SDimitry Andric 2180b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2190b57cec5SDimitry Andricinline 2200b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2210b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 2220b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2230b57cec5SDimitry Andric : __first_{0} 2240b57cec5SDimitry Andric#endif 2250b57cec5SDimitry Andric{ 2260b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2270b57cec5SDimitry Andric _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 2280b57cec5SDimitry Andric#endif 2290b57cec5SDimitry Andric} 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2340b57cec5SDimitry Andricvoid 2350b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 2360b57cec5SDimitry Andric{ 2370b57cec5SDimitry Andric __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 2380b57cec5SDimitry Andric size_t __sz = _Size; 2390b57cec5SDimitry Andric for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 2400b57cec5SDimitry Andric if ( __sz < __bits_per_word) 2410b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 2420b57cec5SDimitry Andric else 2430b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v); 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andric _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 2460b57cec5SDimitry Andric _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 2470b57cec5SDimitry Andric __storage_type(0)); 2480b57cec5SDimitry Andric} 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2510b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2520b57cec5SDimitry Andricvoid 2530b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 2540b57cec5SDimitry Andric{ 2550b57cec5SDimitry Andric __first_[0] = __v; 2560b57cec5SDimitry Andric if (_Size < __bits_per_word) 2570b57cec5SDimitry Andric __first_[0] &= ( 1ULL << _Size ) - 1; 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 2600b57cec5SDimitry Andric} 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2650b57cec5SDimitry Andricinline 2660b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2670b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 2680b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2690b57cec5SDimitry Andric#if __SIZEOF_SIZE_T__ == 8 2700b57cec5SDimitry Andric : __first_{__v} 2710b57cec5SDimitry Andric#elif __SIZEOF_SIZE_T__ == 4 2720b57cec5SDimitry Andric : __first_{static_cast<__storage_type>(__v), 2730b57cec5SDimitry Andric _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 2740b57cec5SDimitry Andric : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 2750b57cec5SDimitry Andric#else 2760b57cec5SDimitry Andric#error This constructor has not been ported to this platform 2770b57cec5SDimitry Andric#endif 2780b57cec5SDimitry Andric#endif 2790b57cec5SDimitry Andric{ 2800b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2810b57cec5SDimitry Andric __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 2820b57cec5SDimitry Andric#endif 2830b57cec5SDimitry Andric} 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2860b57cec5SDimitry Andricinline 2870b57cec5SDimitry Andricvoid 2880b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 2890b57cec5SDimitry Andric{ 2900b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 2910b57cec5SDimitry Andric __first_[__i] &= __v.__first_[__i]; 2920b57cec5SDimitry Andric} 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2950b57cec5SDimitry Andricinline 2960b57cec5SDimitry Andricvoid 2970b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 2980b57cec5SDimitry Andric{ 2990b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3000b57cec5SDimitry Andric __first_[__i] |= __v.__first_[__i]; 3010b57cec5SDimitry Andric} 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3040b57cec5SDimitry Andricinline 3050b57cec5SDimitry Andricvoid 3060b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 3070b57cec5SDimitry Andric{ 3080b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3090b57cec5SDimitry Andric __first_[__i] ^= __v.__first_[__i]; 3100b57cec5SDimitry Andric} 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3130b57cec5SDimitry Andricvoid 3140b57cec5SDimitry Andric__bitset<_N_words, _Size>::flip() _NOEXCEPT 3150b57cec5SDimitry Andric{ 3160b57cec5SDimitry Andric // do middle whole words 3170b57cec5SDimitry Andric size_type __n = _Size; 3180b57cec5SDimitry Andric __storage_pointer __p = __first_; 3190b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3200b57cec5SDimitry Andric *__p = ~*__p; 3210b57cec5SDimitry Andric // do last partial word 3220b57cec5SDimitry Andric if (__n > 0) 3230b57cec5SDimitry Andric { 3240b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3250b57cec5SDimitry Andric __storage_type __b = *__p & __m; 3260b57cec5SDimitry Andric *__p &= ~__m; 3270b57cec5SDimitry Andric *__p |= ~__b & __m; 3280b57cec5SDimitry Andric } 3290b57cec5SDimitry Andric} 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3320b57cec5SDimitry Andricunsigned long 3330b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const 3340b57cec5SDimitry Andric{ 3350b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3360b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 3370b57cec5SDimitry Andric if (__i != __e) 3380b57cec5SDimitry Andric __throw_overflow_error("bitset to_ulong overflow error"); 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andric return __first_[0]; 3410b57cec5SDimitry Andric} 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3440b57cec5SDimitry Andricinline 3450b57cec5SDimitry Andricunsigned long 3460b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const 3470b57cec5SDimitry Andric{ 3480b57cec5SDimitry Andric return __first_[0]; 3490b57cec5SDimitry Andric} 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3520b57cec5SDimitry Andricunsigned long long 3530b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const 3540b57cec5SDimitry Andric{ 3550b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3560b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 3570b57cec5SDimitry Andric if (__i != __e) 3580b57cec5SDimitry Andric __throw_overflow_error("bitset to_ullong overflow error"); 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric return to_ullong(true_type()); 3610b57cec5SDimitry Andric} 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3640b57cec5SDimitry Andricinline 3650b57cec5SDimitry Andricunsigned long long 3660b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const 3670b57cec5SDimitry Andric{ 3680b57cec5SDimitry Andric return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 3690b57cec5SDimitry Andric} 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3720b57cec5SDimitry Andricinline 3730b57cec5SDimitry Andricunsigned long long 3740b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 3750b57cec5SDimitry Andric{ 3760b57cec5SDimitry Andric return __first_[0]; 3770b57cec5SDimitry Andric} 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3800b57cec5SDimitry Andricunsigned long long 3810b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 3820b57cec5SDimitry Andric{ 3830b57cec5SDimitry Andric unsigned long long __r = __first_[0]; 384e8d8bef9SDimitry Andric for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 3850b57cec5SDimitry Andric __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 3860b57cec5SDimitry Andric return __r; 3870b57cec5SDimitry Andric} 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3900b57cec5SDimitry Andricbool 3910b57cec5SDimitry Andric__bitset<_N_words, _Size>::all() const _NOEXCEPT 3920b57cec5SDimitry Andric{ 3930b57cec5SDimitry Andric // do middle whole words 3940b57cec5SDimitry Andric size_type __n = _Size; 3950b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 3960b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3970b57cec5SDimitry Andric if (~*__p) 3980b57cec5SDimitry Andric return false; 3990b57cec5SDimitry Andric // do last partial word 4000b57cec5SDimitry Andric if (__n > 0) 4010b57cec5SDimitry Andric { 4020b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4030b57cec5SDimitry Andric if (~*__p & __m) 4040b57cec5SDimitry Andric return false; 4050b57cec5SDimitry Andric } 4060b57cec5SDimitry Andric return true; 4070b57cec5SDimitry Andric} 4080b57cec5SDimitry Andric 4090b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 4100b57cec5SDimitry Andricbool 4110b57cec5SDimitry Andric__bitset<_N_words, _Size>::any() const _NOEXCEPT 4120b57cec5SDimitry Andric{ 4130b57cec5SDimitry Andric // do middle whole words 4140b57cec5SDimitry Andric size_type __n = _Size; 4150b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4160b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4170b57cec5SDimitry Andric if (*__p) 4180b57cec5SDimitry Andric return true; 4190b57cec5SDimitry Andric // do last partial word 4200b57cec5SDimitry Andric if (__n > 0) 4210b57cec5SDimitry Andric { 4220b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4230b57cec5SDimitry Andric if (*__p & __m) 4240b57cec5SDimitry Andric return true; 4250b57cec5SDimitry Andric } 4260b57cec5SDimitry Andric return false; 4270b57cec5SDimitry Andric} 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 4300b57cec5SDimitry Andricinline 4310b57cec5SDimitry Andricsize_t 4320b57cec5SDimitry Andric__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 4330b57cec5SDimitry Andric{ 4340b57cec5SDimitry Andric size_t __h = 0; 4350b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 4360b57cec5SDimitry Andric __h ^= __first_[__i]; 4370b57cec5SDimitry Andric return __h; 4380b57cec5SDimitry Andric} 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andrictemplate <size_t _Size> 4410b57cec5SDimitry Andricclass __bitset<1, _Size> 4420b57cec5SDimitry Andric{ 4430b57cec5SDimitry Andricpublic: 4440b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 4450b57cec5SDimitry Andric typedef size_t size_type; 4460b57cec5SDimitry Andric typedef size_type __storage_type; 4470b57cec5SDimitry Andricprotected: 4480b57cec5SDimitry Andric typedef __bitset __self; 4490b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 4500b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 4510b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 4540b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 4550b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 4560b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 4570b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 4580b57cec5SDimitry Andric 4590b57cec5SDimitry Andric __storage_type __first_; 4600b57cec5SDimitry Andric 4610b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 4620b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 4630b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 4640b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4670b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 4680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4690b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 4700b57cec5SDimitry Andric 4710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 4720b57cec5SDimitry Andric {return reference(&__first_, __storage_type(1) << __pos);} 4730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 4740b57cec5SDimitry Andric {return const_reference(&__first_, __storage_type(1) << __pos);} 4750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 4760b57cec5SDimitry Andric {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 4770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 4780b57cec5SDimitry Andric {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 4790b57cec5SDimitry Andric 4800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4810b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 4820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4830b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 4840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4850b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 4860b57cec5SDimitry Andric 4870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4880b57cec5SDimitry Andric void flip() _NOEXCEPT; 4890b57cec5SDimitry Andric 4900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4910b57cec5SDimitry Andric unsigned long to_ulong() const; 4920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4930b57cec5SDimitry Andric unsigned long long to_ullong() const; 4940b57cec5SDimitry Andric 4950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4960b57cec5SDimitry Andric bool all() const _NOEXCEPT; 4970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4980b57cec5SDimitry Andric bool any() const _NOEXCEPT; 4990b57cec5SDimitry Andric 5000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5010b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 5020b57cec5SDimitry Andric}; 5030b57cec5SDimitry Andric 5040b57cec5SDimitry Andrictemplate <size_t _Size> 5050b57cec5SDimitry Andricinline 5060b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5070b57cec5SDimitry Andric__bitset<1, _Size>::__bitset() _NOEXCEPT 5080b57cec5SDimitry Andric : __first_(0) 5090b57cec5SDimitry Andric{ 5100b57cec5SDimitry Andric} 5110b57cec5SDimitry Andric 5120b57cec5SDimitry Andrictemplate <size_t _Size> 5130b57cec5SDimitry Andricinline 5140b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5150b57cec5SDimitry Andric__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 5160b57cec5SDimitry Andric : __first_( 5170b57cec5SDimitry Andric _Size == __bits_per_word ? static_cast<__storage_type>(__v) 5180b57cec5SDimitry Andric : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 5190b57cec5SDimitry Andric ) 5200b57cec5SDimitry Andric{ 5210b57cec5SDimitry Andric} 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andrictemplate <size_t _Size> 5240b57cec5SDimitry Andricinline 5250b57cec5SDimitry Andricvoid 5260b57cec5SDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 5270b57cec5SDimitry Andric{ 5280b57cec5SDimitry Andric __first_ &= __v.__first_; 5290b57cec5SDimitry Andric} 5300b57cec5SDimitry Andric 5310b57cec5SDimitry Andrictemplate <size_t _Size> 5320b57cec5SDimitry Andricinline 5330b57cec5SDimitry Andricvoid 5340b57cec5SDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 5350b57cec5SDimitry Andric{ 5360b57cec5SDimitry Andric __first_ |= __v.__first_; 5370b57cec5SDimitry Andric} 5380b57cec5SDimitry Andric 5390b57cec5SDimitry Andrictemplate <size_t _Size> 5400b57cec5SDimitry Andricinline 5410b57cec5SDimitry Andricvoid 5420b57cec5SDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 5430b57cec5SDimitry Andric{ 5440b57cec5SDimitry Andric __first_ ^= __v.__first_; 5450b57cec5SDimitry Andric} 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andrictemplate <size_t _Size> 5480b57cec5SDimitry Andricinline 5490b57cec5SDimitry Andricvoid 5500b57cec5SDimitry Andric__bitset<1, _Size>::flip() _NOEXCEPT 5510b57cec5SDimitry Andric{ 5520b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5530b57cec5SDimitry Andric __first_ = ~__first_; 5540b57cec5SDimitry Andric __first_ &= __m; 5550b57cec5SDimitry Andric} 5560b57cec5SDimitry Andric 5570b57cec5SDimitry Andrictemplate <size_t _Size> 5580b57cec5SDimitry Andricinline 5590b57cec5SDimitry Andricunsigned long 5600b57cec5SDimitry Andric__bitset<1, _Size>::to_ulong() const 5610b57cec5SDimitry Andric{ 5620b57cec5SDimitry Andric return __first_; 5630b57cec5SDimitry Andric} 5640b57cec5SDimitry Andric 5650b57cec5SDimitry Andrictemplate <size_t _Size> 5660b57cec5SDimitry Andricinline 5670b57cec5SDimitry Andricunsigned long long 5680b57cec5SDimitry Andric__bitset<1, _Size>::to_ullong() const 5690b57cec5SDimitry Andric{ 5700b57cec5SDimitry Andric return __first_; 5710b57cec5SDimitry Andric} 5720b57cec5SDimitry Andric 5730b57cec5SDimitry Andrictemplate <size_t _Size> 5740b57cec5SDimitry Andricinline 5750b57cec5SDimitry Andricbool 5760b57cec5SDimitry Andric__bitset<1, _Size>::all() const _NOEXCEPT 5770b57cec5SDimitry Andric{ 5780b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5790b57cec5SDimitry Andric return !(~__first_ & __m); 5800b57cec5SDimitry Andric} 5810b57cec5SDimitry Andric 5820b57cec5SDimitry Andrictemplate <size_t _Size> 5830b57cec5SDimitry Andricinline 5840b57cec5SDimitry Andricbool 5850b57cec5SDimitry Andric__bitset<1, _Size>::any() const _NOEXCEPT 5860b57cec5SDimitry Andric{ 5870b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5880b57cec5SDimitry Andric return __first_ & __m; 5890b57cec5SDimitry Andric} 5900b57cec5SDimitry Andric 5910b57cec5SDimitry Andrictemplate <size_t _Size> 5920b57cec5SDimitry Andricinline 5930b57cec5SDimitry Andricsize_t 5940b57cec5SDimitry Andric__bitset<1, _Size>::__hash_code() const _NOEXCEPT 5950b57cec5SDimitry Andric{ 5960b57cec5SDimitry Andric return __first_; 5970b57cec5SDimitry Andric} 5980b57cec5SDimitry Andric 5990b57cec5SDimitry Andrictemplate <> 6000b57cec5SDimitry Andricclass __bitset<0, 0> 6010b57cec5SDimitry Andric{ 6020b57cec5SDimitry Andricpublic: 6030b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 6040b57cec5SDimitry Andric typedef size_t size_type; 6050b57cec5SDimitry Andric typedef size_type __storage_type; 6060b57cec5SDimitry Andricprotected: 6070b57cec5SDimitry Andric typedef __bitset __self; 6080b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 6090b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 6100b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 6110b57cec5SDimitry Andric 6120b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 6130b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 6140b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 6150b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 6160b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 6170b57cec5SDimitry Andric 6180b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 6190b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 6200b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 6210b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 6220b57cec5SDimitry Andric 6230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6240b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 6250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6260b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 6270b57cec5SDimitry Andric 6280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT 629e8d8bef9SDimitry Andric {return reference(nullptr, 1);} 6300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 631e8d8bef9SDimitry Andric {return const_reference(nullptr, 1);} 6320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT 633e8d8bef9SDimitry Andric {return iterator(nullptr, 0);} 6340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT 635e8d8bef9SDimitry Andric {return const_iterator(nullptr, 0);} 6360b57cec5SDimitry Andric 6370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} 6380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} 6390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} 6400b57cec5SDimitry Andric 6410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} 6440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} 6470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} 6480b57cec5SDimitry Andric 6490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 6500b57cec5SDimitry Andric}; 6510b57cec5SDimitry Andric 6520b57cec5SDimitry Andricinline 6530b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6540b57cec5SDimitry Andric__bitset<0, 0>::__bitset() _NOEXCEPT 6550b57cec5SDimitry Andric{ 6560b57cec5SDimitry Andric} 6570b57cec5SDimitry Andric 6580b57cec5SDimitry Andricinline 6590b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6600b57cec5SDimitry Andric__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 6610b57cec5SDimitry Andric{ 6620b57cec5SDimitry Andric} 6630b57cec5SDimitry Andric 6640b57cec5SDimitry Andrictemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 6650b57cec5SDimitry Andrictemplate <size_t _Size> struct hash<bitset<_Size> >; 6660b57cec5SDimitry Andric 6670b57cec5SDimitry Andrictemplate <size_t _Size> 6680b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset 6690b57cec5SDimitry Andric : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 6700b57cec5SDimitry Andric{ 6710b57cec5SDimitry Andricpublic: 6720b57cec5SDimitry Andric static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 6730b57cec5SDimitry Andric typedef __bitset<__n_words, _Size> base; 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andricpublic: 6760b57cec5SDimitry Andric typedef typename base::reference reference; 6770b57cec5SDimitry Andric typedef typename base::const_reference const_reference; 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric // 23.3.5.1 constructors: 6800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 6810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 6820b57cec5SDimitry Andric bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 683349cc55cSDimitry Andric template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> > 6840b57cec5SDimitry Andric explicit bitset(const _CharT* __str, 6850b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 6860b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 6870b57cec5SDimitry Andric template<class _CharT, class _Traits, class _Allocator> 6880b57cec5SDimitry Andric explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 6890b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 6900b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 6910b57cec5SDimitry Andric (basic_string<_CharT,_Traits,_Allocator>::npos), 6920b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 6950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6960b57cec5SDimitry Andric bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 6970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6980b57cec5SDimitry Andric bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 6990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7000b57cec5SDimitry Andric bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 7010b57cec5SDimitry Andric bitset& operator<<=(size_t __pos) _NOEXCEPT; 7020b57cec5SDimitry Andric bitset& operator>>=(size_t __pos) _NOEXCEPT; 7030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7040b57cec5SDimitry Andric bitset& set() _NOEXCEPT; 7050b57cec5SDimitry Andric bitset& set(size_t __pos, bool __val = true); 7060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7070b57cec5SDimitry Andric bitset& reset() _NOEXCEPT; 7080b57cec5SDimitry Andric bitset& reset(size_t __pos); 7090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7100b57cec5SDimitry Andric bitset operator~() const _NOEXCEPT; 7110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7120b57cec5SDimitry Andric bitset& flip() _NOEXCEPT; 7130b57cec5SDimitry Andric bitset& flip(size_t __pos); 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric // element access: 7160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 7170b57cec5SDimitry Andric const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 7180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} 7190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7200b57cec5SDimitry Andric unsigned long to_ulong() const; 7210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7220b57cec5SDimitry Andric unsigned long long to_ullong() const; 7230b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 7240b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 7250b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7260b57cec5SDimitry Andric template <class _CharT, class _Traits> 7270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7280b57cec5SDimitry Andric basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 7290b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7300b57cec5SDimitry Andric template <class _CharT> 7310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7320b57cec5SDimitry Andric basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 7330b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7350b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 7360b57cec5SDimitry Andric char __one = '1') const; 7370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7380b57cec5SDimitry Andric size_t count() const _NOEXCEPT; 7390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 7400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7410b57cec5SDimitry Andric bool operator==(const bitset& __rhs) const _NOEXCEPT; 7420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7430b57cec5SDimitry Andric bool operator!=(const bitset& __rhs) const _NOEXCEPT; 7440b57cec5SDimitry Andric bool test(size_t __pos) const; 7450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7460b57cec5SDimitry Andric bool all() const _NOEXCEPT; 7470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7480b57cec5SDimitry Andric bool any() const _NOEXCEPT; 7490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} 7500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7510b57cec5SDimitry Andric bitset operator<<(size_t __pos) const _NOEXCEPT; 7520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7530b57cec5SDimitry Andric bitset operator>>(size_t __pos) const _NOEXCEPT; 7540b57cec5SDimitry Andric 7550b57cec5SDimitry Andricprivate: 7560b57cec5SDimitry Andric 7570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7580b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 7590b57cec5SDimitry Andric 7600b57cec5SDimitry Andric friend struct hash<bitset>; 7610b57cec5SDimitry Andric}; 7620b57cec5SDimitry Andric 7630b57cec5SDimitry Andrictemplate <size_t _Size> 7640b57cec5SDimitry Andrictemplate<class _CharT, class> 7650b57cec5SDimitry Andricbitset<_Size>::bitset(const _CharT* __str, 7660b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n, 7670b57cec5SDimitry Andric _CharT __zero, _CharT __one) 7680b57cec5SDimitry Andric{ 7690b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 7700b57cec5SDimitry Andric for (size_t __i = 0; __i < __rlen; ++__i) 7710b57cec5SDimitry Andric if (__str[__i] != __zero && __str[__i] != __one) 7720b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 7730b57cec5SDimitry Andric 7740b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 7750b57cec5SDimitry Andric size_t __i = 0; 7760b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 7770b57cec5SDimitry Andric { 7780b57cec5SDimitry Andric _CharT __c = __str[_Mp - 1 - __i]; 779fe6060f1SDimitry Andric (*this)[__i] = (__c == __one); 7800b57cec5SDimitry Andric } 7810b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 7820b57cec5SDimitry Andric} 7830b57cec5SDimitry Andric 7840b57cec5SDimitry Andrictemplate <size_t _Size> 7850b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 7860b57cec5SDimitry Andricbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 7870b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 7880b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 7890b57cec5SDimitry Andric _CharT __zero, _CharT __one) 7900b57cec5SDimitry Andric{ 7910b57cec5SDimitry Andric if (__pos > __str.size()) 7920b57cec5SDimitry Andric __throw_out_of_range("bitset string pos out of range"); 7930b57cec5SDimitry Andric 7940b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 7950b57cec5SDimitry Andric for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 7960b57cec5SDimitry Andric if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 7970b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 8000b57cec5SDimitry Andric size_t __i = 0; 8010b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 8020b57cec5SDimitry Andric { 8030b57cec5SDimitry Andric _CharT __c = __str[__pos + _Mp - 1 - __i]; 804fe6060f1SDimitry Andric (*this)[__i] = _Traits::eq(__c, __one); 8050b57cec5SDimitry Andric } 8060b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 8070b57cec5SDimitry Andric} 8080b57cec5SDimitry Andric 8090b57cec5SDimitry Andrictemplate <size_t _Size> 8100b57cec5SDimitry Andricinline 8110b57cec5SDimitry Andricbitset<_Size>& 8120b57cec5SDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 8130b57cec5SDimitry Andric{ 8140b57cec5SDimitry Andric base::operator&=(__rhs); 8150b57cec5SDimitry Andric return *this; 8160b57cec5SDimitry Andric} 8170b57cec5SDimitry Andric 8180b57cec5SDimitry Andrictemplate <size_t _Size> 8190b57cec5SDimitry Andricinline 8200b57cec5SDimitry Andricbitset<_Size>& 8210b57cec5SDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 8220b57cec5SDimitry Andric{ 8230b57cec5SDimitry Andric base::operator|=(__rhs); 8240b57cec5SDimitry Andric return *this; 8250b57cec5SDimitry Andric} 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andrictemplate <size_t _Size> 8280b57cec5SDimitry Andricinline 8290b57cec5SDimitry Andricbitset<_Size>& 8300b57cec5SDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 8310b57cec5SDimitry Andric{ 8320b57cec5SDimitry Andric base::operator^=(__rhs); 8330b57cec5SDimitry Andric return *this; 8340b57cec5SDimitry Andric} 8350b57cec5SDimitry Andric 8360b57cec5SDimitry Andrictemplate <size_t _Size> 8370b57cec5SDimitry Andricbitset<_Size>& 8380b57cec5SDimitry Andricbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 8390b57cec5SDimitry Andric{ 8400b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 8410b57cec5SDimitry Andric _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 8420b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), __pos, false); 8430b57cec5SDimitry Andric return *this; 8440b57cec5SDimitry Andric} 8450b57cec5SDimitry Andric 8460b57cec5SDimitry Andrictemplate <size_t _Size> 8470b57cec5SDimitry Andricbitset<_Size>& 8480b57cec5SDimitry Andricbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 8490b57cec5SDimitry Andric{ 8500b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 8510b57cec5SDimitry Andric _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 8520b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 8530b57cec5SDimitry Andric return *this; 8540b57cec5SDimitry Andric} 8550b57cec5SDimitry Andric 8560b57cec5SDimitry Andrictemplate <size_t _Size> 8570b57cec5SDimitry Andricinline 8580b57cec5SDimitry Andricbitset<_Size>& 8590b57cec5SDimitry Andricbitset<_Size>::set() _NOEXCEPT 8600b57cec5SDimitry Andric{ 8610b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, true); 8620b57cec5SDimitry Andric return *this; 8630b57cec5SDimitry Andric} 8640b57cec5SDimitry Andric 8650b57cec5SDimitry Andrictemplate <size_t _Size> 8660b57cec5SDimitry Andricbitset<_Size>& 8670b57cec5SDimitry Andricbitset<_Size>::set(size_t __pos, bool __val) 8680b57cec5SDimitry Andric{ 8690b57cec5SDimitry Andric if (__pos >= _Size) 8700b57cec5SDimitry Andric __throw_out_of_range("bitset set argument out of range"); 8710b57cec5SDimitry Andric 8720b57cec5SDimitry Andric (*this)[__pos] = __val; 8730b57cec5SDimitry Andric return *this; 8740b57cec5SDimitry Andric} 8750b57cec5SDimitry Andric 8760b57cec5SDimitry Andrictemplate <size_t _Size> 8770b57cec5SDimitry Andricinline 8780b57cec5SDimitry Andricbitset<_Size>& 8790b57cec5SDimitry Andricbitset<_Size>::reset() _NOEXCEPT 8800b57cec5SDimitry Andric{ 8810b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, false); 8820b57cec5SDimitry Andric return *this; 8830b57cec5SDimitry Andric} 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andrictemplate <size_t _Size> 8860b57cec5SDimitry Andricbitset<_Size>& 8870b57cec5SDimitry Andricbitset<_Size>::reset(size_t __pos) 8880b57cec5SDimitry Andric{ 8890b57cec5SDimitry Andric if (__pos >= _Size) 8900b57cec5SDimitry Andric __throw_out_of_range("bitset reset argument out of range"); 8910b57cec5SDimitry Andric 8920b57cec5SDimitry Andric (*this)[__pos] = false; 8930b57cec5SDimitry Andric return *this; 8940b57cec5SDimitry Andric} 8950b57cec5SDimitry Andric 8960b57cec5SDimitry Andrictemplate <size_t _Size> 8970b57cec5SDimitry Andricinline 8980b57cec5SDimitry Andricbitset<_Size> 8990b57cec5SDimitry Andricbitset<_Size>::operator~() const _NOEXCEPT 9000b57cec5SDimitry Andric{ 9010b57cec5SDimitry Andric bitset __x(*this); 9020b57cec5SDimitry Andric __x.flip(); 9030b57cec5SDimitry Andric return __x; 9040b57cec5SDimitry Andric} 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andrictemplate <size_t _Size> 9070b57cec5SDimitry Andricinline 9080b57cec5SDimitry Andricbitset<_Size>& 9090b57cec5SDimitry Andricbitset<_Size>::flip() _NOEXCEPT 9100b57cec5SDimitry Andric{ 9110b57cec5SDimitry Andric base::flip(); 9120b57cec5SDimitry Andric return *this; 9130b57cec5SDimitry Andric} 9140b57cec5SDimitry Andric 9150b57cec5SDimitry Andrictemplate <size_t _Size> 9160b57cec5SDimitry Andricbitset<_Size>& 9170b57cec5SDimitry Andricbitset<_Size>::flip(size_t __pos) 9180b57cec5SDimitry Andric{ 9190b57cec5SDimitry Andric if (__pos >= _Size) 9200b57cec5SDimitry Andric __throw_out_of_range("bitset flip argument out of range"); 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andric reference r = base::__make_ref(__pos); 9230b57cec5SDimitry Andric r = ~r; 9240b57cec5SDimitry Andric return *this; 9250b57cec5SDimitry Andric} 9260b57cec5SDimitry Andric 9270b57cec5SDimitry Andrictemplate <size_t _Size> 9280b57cec5SDimitry Andricinline 9290b57cec5SDimitry Andricunsigned long 9300b57cec5SDimitry Andricbitset<_Size>::to_ulong() const 9310b57cec5SDimitry Andric{ 9320b57cec5SDimitry Andric return base::to_ulong(); 9330b57cec5SDimitry Andric} 9340b57cec5SDimitry Andric 9350b57cec5SDimitry Andrictemplate <size_t _Size> 9360b57cec5SDimitry Andricinline 9370b57cec5SDimitry Andricunsigned long long 9380b57cec5SDimitry Andricbitset<_Size>::to_ullong() const 9390b57cec5SDimitry Andric{ 9400b57cec5SDimitry Andric return base::to_ullong(); 9410b57cec5SDimitry Andric} 9420b57cec5SDimitry Andric 9430b57cec5SDimitry Andrictemplate <size_t _Size> 9440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 9450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 9460b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 9470b57cec5SDimitry Andric{ 9480b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 9490b57cec5SDimitry Andric for (size_t __i = 0; __i < _Size; ++__i) 9500b57cec5SDimitry Andric { 9510b57cec5SDimitry Andric if ((*this)[__i]) 9520b57cec5SDimitry Andric __r[_Size - 1 - __i] = __one; 9530b57cec5SDimitry Andric } 9540b57cec5SDimitry Andric return __r; 9550b57cec5SDimitry Andric} 9560b57cec5SDimitry Andric 9570b57cec5SDimitry Andrictemplate <size_t _Size> 9580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 9590b57cec5SDimitry Andricinline 9600b57cec5SDimitry Andricbasic_string<_CharT, _Traits, allocator<_CharT> > 9610b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 9620b57cec5SDimitry Andric{ 9630b57cec5SDimitry Andric return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 9640b57cec5SDimitry Andric} 9650b57cec5SDimitry Andric 9660b57cec5SDimitry Andrictemplate <size_t _Size> 9670b57cec5SDimitry Andrictemplate <class _CharT> 9680b57cec5SDimitry Andricinline 9690b57cec5SDimitry Andricbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 9700b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 9710b57cec5SDimitry Andric{ 9720b57cec5SDimitry Andric return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 9730b57cec5SDimitry Andric} 9740b57cec5SDimitry Andric 9750b57cec5SDimitry Andrictemplate <size_t _Size> 9760b57cec5SDimitry Andricinline 9770b57cec5SDimitry Andricbasic_string<char, char_traits<char>, allocator<char> > 9780b57cec5SDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const 9790b57cec5SDimitry Andric{ 9800b57cec5SDimitry Andric return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 9810b57cec5SDimitry Andric} 9820b57cec5SDimitry Andric 9830b57cec5SDimitry Andrictemplate <size_t _Size> 9840b57cec5SDimitry Andricinline 9850b57cec5SDimitry Andricsize_t 9860b57cec5SDimitry Andricbitset<_Size>::count() const _NOEXCEPT 9870b57cec5SDimitry Andric{ 988e8d8bef9SDimitry Andric return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size)); 9890b57cec5SDimitry Andric} 9900b57cec5SDimitry Andric 9910b57cec5SDimitry Andrictemplate <size_t _Size> 9920b57cec5SDimitry Andricinline 9930b57cec5SDimitry Andricbool 9940b57cec5SDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 9950b57cec5SDimitry Andric{ 9960b57cec5SDimitry Andric return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 9970b57cec5SDimitry Andric} 9980b57cec5SDimitry Andric 9990b57cec5SDimitry Andrictemplate <size_t _Size> 10000b57cec5SDimitry Andricinline 10010b57cec5SDimitry Andricbool 10020b57cec5SDimitry Andricbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 10030b57cec5SDimitry Andric{ 10040b57cec5SDimitry Andric return !(*this == __rhs); 10050b57cec5SDimitry Andric} 10060b57cec5SDimitry Andric 10070b57cec5SDimitry Andrictemplate <size_t _Size> 10080b57cec5SDimitry Andricbool 10090b57cec5SDimitry Andricbitset<_Size>::test(size_t __pos) const 10100b57cec5SDimitry Andric{ 10110b57cec5SDimitry Andric if (__pos >= _Size) 10120b57cec5SDimitry Andric __throw_out_of_range("bitset test argument out of range"); 10130b57cec5SDimitry Andric 10140b57cec5SDimitry Andric return (*this)[__pos]; 10150b57cec5SDimitry Andric} 10160b57cec5SDimitry Andric 10170b57cec5SDimitry Andrictemplate <size_t _Size> 10180b57cec5SDimitry Andricinline 10190b57cec5SDimitry Andricbool 10200b57cec5SDimitry Andricbitset<_Size>::all() const _NOEXCEPT 10210b57cec5SDimitry Andric{ 10220b57cec5SDimitry Andric return base::all(); 10230b57cec5SDimitry Andric} 10240b57cec5SDimitry Andric 10250b57cec5SDimitry Andrictemplate <size_t _Size> 10260b57cec5SDimitry Andricinline 10270b57cec5SDimitry Andricbool 10280b57cec5SDimitry Andricbitset<_Size>::any() const _NOEXCEPT 10290b57cec5SDimitry Andric{ 10300b57cec5SDimitry Andric return base::any(); 10310b57cec5SDimitry Andric} 10320b57cec5SDimitry Andric 10330b57cec5SDimitry Andrictemplate <size_t _Size> 10340b57cec5SDimitry Andricinline 10350b57cec5SDimitry Andricbitset<_Size> 10360b57cec5SDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 10370b57cec5SDimitry Andric{ 10380b57cec5SDimitry Andric bitset __r = *this; 10390b57cec5SDimitry Andric __r <<= __pos; 10400b57cec5SDimitry Andric return __r; 10410b57cec5SDimitry Andric} 10420b57cec5SDimitry Andric 10430b57cec5SDimitry Andrictemplate <size_t _Size> 10440b57cec5SDimitry Andricinline 10450b57cec5SDimitry Andricbitset<_Size> 10460b57cec5SDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 10470b57cec5SDimitry Andric{ 10480b57cec5SDimitry Andric bitset __r = *this; 10490b57cec5SDimitry Andric __r >>= __pos; 10500b57cec5SDimitry Andric return __r; 10510b57cec5SDimitry Andric} 10520b57cec5SDimitry Andric 10530b57cec5SDimitry Andrictemplate <size_t _Size> 10540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10550b57cec5SDimitry Andricbitset<_Size> 10560b57cec5SDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 10570b57cec5SDimitry Andric{ 10580b57cec5SDimitry Andric bitset<_Size> __r = __x; 10590b57cec5SDimitry Andric __r &= __y; 10600b57cec5SDimitry Andric return __r; 10610b57cec5SDimitry Andric} 10620b57cec5SDimitry Andric 10630b57cec5SDimitry Andrictemplate <size_t _Size> 10640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10650b57cec5SDimitry Andricbitset<_Size> 10660b57cec5SDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 10670b57cec5SDimitry Andric{ 10680b57cec5SDimitry Andric bitset<_Size> __r = __x; 10690b57cec5SDimitry Andric __r |= __y; 10700b57cec5SDimitry Andric return __r; 10710b57cec5SDimitry Andric} 10720b57cec5SDimitry Andric 10730b57cec5SDimitry Andrictemplate <size_t _Size> 10740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10750b57cec5SDimitry Andricbitset<_Size> 10760b57cec5SDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 10770b57cec5SDimitry Andric{ 10780b57cec5SDimitry Andric bitset<_Size> __r = __x; 10790b57cec5SDimitry Andric __r ^= __y; 10800b57cec5SDimitry Andric return __r; 10810b57cec5SDimitry Andric} 10820b57cec5SDimitry Andric 10830b57cec5SDimitry Andrictemplate <size_t _Size> 10840b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 10850b57cec5SDimitry Andric : public unary_function<bitset<_Size>, size_t> 10860b57cec5SDimitry Andric{ 10870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10880b57cec5SDimitry Andric size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 10890b57cec5SDimitry Andric {return __bs.__hash_code();} 10900b57cec5SDimitry Andric}; 10910b57cec5SDimitry Andric 10920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 10930b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 10940b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 10950b57cec5SDimitry Andric 10960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 10970b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 10980b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 10990b57cec5SDimitry Andric 11000b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 11010b57cec5SDimitry Andric 11020b57cec5SDimitry Andric_LIBCPP_POP_MACROS 11030b57cec5SDimitry Andric 11040b57cec5SDimitry Andric#endif // _LIBCPP_BITSET 1105