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