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