xref: /freebsd-12.1/contrib/libc++/include/bitset (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===---------------------------- bitset ----------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_BITSET
127a984708SDavid Chisnall#define _LIBCPP_BITSET
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    bitset synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnallnamespace std
187a984708SDavid Chisnall{
197a984708SDavid Chisnall
207a984708SDavid Chisnallnamespace std {
217a984708SDavid Chisnall
227a984708SDavid Chisnalltemplate <size_t N>
237a984708SDavid Chisnallclass bitset
247a984708SDavid Chisnall{
257a984708SDavid Chisnallpublic:
267a984708SDavid Chisnall    // bit reference:
277a984708SDavid Chisnall    class reference
287a984708SDavid Chisnall    {
297a984708SDavid Chisnall        friend class bitset;
307a984708SDavid Chisnall        reference() noexcept;
317a984708SDavid Chisnall    public:
327a984708SDavid Chisnall        ~reference() noexcept;
337a984708SDavid Chisnall        reference& operator=(bool x) noexcept;           // for b[i] = x;
347a984708SDavid Chisnall        reference& operator=(const reference&) noexcept; // for b[i] = b[j];
357a984708SDavid Chisnall        bool operator~() const noexcept;                 // flips the bit
367a984708SDavid Chisnall        operator bool() const noexcept;                  // for x = b[i];
377a984708SDavid Chisnall        reference& flip() noexcept;                      // for b[i].flip();
387a984708SDavid Chisnall    };
397a984708SDavid Chisnall
407a984708SDavid Chisnall    // 23.3.5.1 constructors:
417a984708SDavid Chisnall    constexpr bitset() noexcept;
427a984708SDavid Chisnall    constexpr bitset(unsigned long long val) noexcept;
437a984708SDavid Chisnall    template <class charT>
447a984708SDavid Chisnall        explicit bitset(const charT* str,
457a984708SDavid Chisnall                        typename basic_string<charT>::size_type n = basic_string<charT>::npos,
467a984708SDavid Chisnall                        charT zero = charT('0'), charT one = charT('1'));
477a984708SDavid Chisnall    template<class charT, class traits, class Allocator>
487a984708SDavid Chisnall        explicit bitset(const basic_string<charT,traits,Allocator>& str,
497a984708SDavid Chisnall                        typename basic_string<charT,traits,Allocator>::size_type pos = 0,
507a984708SDavid Chisnall                        typename basic_string<charT,traits,Allocator>::size_type n =
517a984708SDavid Chisnall                                 basic_string<charT,traits,Allocator>::npos,
527a984708SDavid Chisnall                        charT zero = charT('0'), charT one = charT('1'));
537a984708SDavid Chisnall
547a984708SDavid Chisnall    // 23.3.5.2 bitset operations:
557a984708SDavid Chisnall    bitset& operator&=(const bitset& rhs) noexcept;
567a984708SDavid Chisnall    bitset& operator|=(const bitset& rhs) noexcept;
577a984708SDavid Chisnall    bitset& operator^=(const bitset& rhs) noexcept;
587a984708SDavid Chisnall    bitset& operator<<=(size_t pos) noexcept;
597a984708SDavid Chisnall    bitset& operator>>=(size_t pos) noexcept;
607a984708SDavid Chisnall    bitset& set() noexcept;
617a984708SDavid Chisnall    bitset& set(size_t pos, bool val = true);
627a984708SDavid Chisnall    bitset& reset() noexcept;
637a984708SDavid Chisnall    bitset& reset(size_t pos);
647a984708SDavid Chisnall    bitset operator~() const noexcept;
657a984708SDavid Chisnall    bitset& flip() noexcept;
667a984708SDavid Chisnall    bitset& flip(size_t pos);
677a984708SDavid Chisnall
687a984708SDavid Chisnall    // element access:
697a984708SDavid Chisnall    constexpr bool operator[](size_t pos) const; // for b[i];
707a984708SDavid Chisnall    reference operator[](size_t pos);            // for b[i];
717a984708SDavid Chisnall    unsigned long to_ulong() const;
727a984708SDavid Chisnall    unsigned long long to_ullong() const;
737a984708SDavid Chisnall    template <class charT, class traits, class Allocator>
747a984708SDavid Chisnall        basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
757a984708SDavid Chisnall    template <class charT, class traits>
767a984708SDavid Chisnall        basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
777a984708SDavid Chisnall    template <class charT>
787a984708SDavid Chisnall        basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
797a984708SDavid Chisnall    basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
807a984708SDavid Chisnall    size_t count() const noexcept;
817a984708SDavid Chisnall    constexpr size_t size() const noexcept;
827a984708SDavid Chisnall    bool operator==(const bitset& rhs) const noexcept;
837a984708SDavid Chisnall    bool operator!=(const bitset& rhs) const noexcept;
847a984708SDavid Chisnall    bool test(size_t pos) const;
857a984708SDavid Chisnall    bool all() const noexcept;
867a984708SDavid Chisnall    bool any() const noexcept;
877a984708SDavid Chisnall    bool none() const noexcept;
887a984708SDavid Chisnall    bitset operator<<(size_t pos) const noexcept;
897a984708SDavid Chisnall    bitset operator>>(size_t pos) const noexcept;
907a984708SDavid Chisnall};
917a984708SDavid Chisnall
927a984708SDavid Chisnall// 23.3.5.3 bitset operators:
937a984708SDavid Chisnalltemplate <size_t N>
947a984708SDavid Chisnallbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
957a984708SDavid Chisnall
967a984708SDavid Chisnalltemplate <size_t N>
977a984708SDavid Chisnallbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
987a984708SDavid Chisnall
997a984708SDavid Chisnalltemplate <size_t N>
1007a984708SDavid Chisnallbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
1017a984708SDavid Chisnall
1027a984708SDavid Chisnalltemplate <class charT, class traits, size_t N>
1037a984708SDavid Chisnallbasic_istream<charT, traits>&
1047a984708SDavid Chisnalloperator>>(basic_istream<charT, traits>& is, bitset<N>& x);
1057a984708SDavid Chisnall
1067a984708SDavid Chisnalltemplate <class charT, class traits, size_t N>
1077a984708SDavid Chisnallbasic_ostream<charT, traits>&
1087a984708SDavid Chisnalloperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
1097a984708SDavid Chisnall
1107a984708SDavid Chisnalltemplate <size_t N> struct hash<std::bitset<N>>;
1117a984708SDavid Chisnall
1127a984708SDavid Chisnall}  // std
1137a984708SDavid Chisnall
1147a984708SDavid Chisnall*/
1157a984708SDavid Chisnall
1167a984708SDavid Chisnall#include <__config>
1177a984708SDavid Chisnall#include <__bit_reference>
1187a984708SDavid Chisnall#include <cstddef>
1197a984708SDavid Chisnall#include <climits>
1207a984708SDavid Chisnall#include <string>
1217a984708SDavid Chisnall#include <stdexcept>
1227a984708SDavid Chisnall#include <iosfwd>
1237a984708SDavid Chisnall#include <__functional_base>
1247a984708SDavid Chisnall
125f9448bf3SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
126f9448bf3SDimitry Andric#pragma GCC system_header
127f9448bf3SDimitry Andric#endif
128f9448bf3SDimitry Andric
129f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS
130f9448bf3SDimitry Andric#include <__undef_macros>
131f9448bf3SDimitry Andric
13294e3ee44SDavid Chisnall
1337a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
1347a984708SDavid Chisnall
1357a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
1367a984708SDavid Chisnallclass __bitset;
1377a984708SDavid Chisnall
1387a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
1397a984708SDavid Chisnallstruct __has_storage_type<__bitset<_N_words, _Size> >
1407a984708SDavid Chisnall{
1417a984708SDavid Chisnall    static const bool value = true;
1427a984708SDavid Chisnall};
1437a984708SDavid Chisnall
1447a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
1457a984708SDavid Chisnallclass __bitset
1467a984708SDavid Chisnall{
1477a984708SDavid Chisnallpublic:
1487a984708SDavid Chisnall    typedef ptrdiff_t              difference_type;
1497a984708SDavid Chisnall    typedef size_t                 size_type;
150936e9439SDimitry Andric    typedef size_type              __storage_type;
1517a984708SDavid Chisnallprotected:
1527a984708SDavid Chisnall    typedef __bitset __self;
1537a984708SDavid Chisnall    typedef       __storage_type*  __storage_pointer;
1547a984708SDavid Chisnall    typedef const __storage_type*  __const_storage_pointer;
1557a984708SDavid Chisnall    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1567a984708SDavid Chisnall
1577a984708SDavid Chisnall    friend class __bit_reference<__bitset>;
1587a984708SDavid Chisnall    friend class __bit_const_reference<__bitset>;
1597a984708SDavid Chisnall    friend class __bit_iterator<__bitset, false>;
1607a984708SDavid Chisnall    friend class __bit_iterator<__bitset, true>;
161936e9439SDimitry Andric    friend struct __bit_array<__bitset>;
1627a984708SDavid Chisnall
1637a984708SDavid Chisnall    __storage_type __first_[_N_words];
1647a984708SDavid Chisnall
1657a984708SDavid Chisnall    typedef __bit_reference<__bitset>                  reference;
1667a984708SDavid Chisnall    typedef __bit_const_reference<__bitset>            const_reference;
1677a984708SDavid Chisnall    typedef __bit_iterator<__bitset, false>            iterator;
1687a984708SDavid Chisnall    typedef __bit_iterator<__bitset, true>             const_iterator;
1697a984708SDavid Chisnall
1709729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
171936e9439SDimitry Andric    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
1729729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
173936e9439SDimitry Andric    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
1747a984708SDavid Chisnall
1757a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
1767a984708SDavid Chisnall        {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
177936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
1787a984708SDavid Chisnall        {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
1797a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
1807a984708SDavid Chisnall        {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
1817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
1827a984708SDavid Chisnall        {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
1837a984708SDavid Chisnall
1849729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1857a984708SDavid Chisnall    void operator&=(const __bitset& __v) _NOEXCEPT;
1869729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1877a984708SDavid Chisnall    void operator|=(const __bitset& __v) _NOEXCEPT;
1889729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1897a984708SDavid Chisnall    void operator^=(const __bitset& __v) _NOEXCEPT;
1907a984708SDavid Chisnall
1917a984708SDavid Chisnall    void flip() _NOEXCEPT;
1927a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
1937a984708SDavid Chisnall        {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
1947a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
1957a984708SDavid Chisnall        {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
1967a984708SDavid Chisnall
1977a984708SDavid Chisnall    bool all() const _NOEXCEPT;
1987a984708SDavid Chisnall    bool any() const _NOEXCEPT;
1999729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2007a984708SDavid Chisnall    size_t __hash_code() const _NOEXCEPT;
2017a984708SDavid Chisnallprivate:
202540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2037a984708SDavid Chisnall    void __init(unsigned long long __v, false_type) _NOEXCEPT;
2049729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2057a984708SDavid Chisnall    void __init(unsigned long long __v, true_type) _NOEXCEPT;
206540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
2077a984708SDavid Chisnall    unsigned long to_ulong(false_type) const;
2089729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2097a984708SDavid Chisnall    unsigned long to_ulong(true_type) const;
2107a984708SDavid Chisnall    unsigned long long to_ullong(false_type) const;
2119729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2127a984708SDavid Chisnall    unsigned long long to_ullong(true_type) const;
2139729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2147a984708SDavid Chisnall    unsigned long long to_ullong(true_type, false_type) const;
2157a984708SDavid Chisnall    unsigned long long to_ullong(true_type, true_type) const;
2167a984708SDavid Chisnall};
2177a984708SDavid Chisnall
2187a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2199729cf09SDimitry Andricinline
220936e9439SDimitry Andric_LIBCPP_CONSTEXPR
2217a984708SDavid Chisnall__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
222540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
223936e9439SDimitry Andric    : __first_{0}
224936e9439SDimitry Andric#endif
2257a984708SDavid Chisnall{
226540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2277a984708SDavid Chisnall    _VSTD::fill_n(__first_, _N_words, __storage_type(0));
228936e9439SDimitry Andric#endif
2297a984708SDavid Chisnall}
2307a984708SDavid Chisnall
231540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG
232936e9439SDimitry Andric
2337a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2347a984708SDavid Chisnallvoid
23594e3ee44SDavid Chisnall__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
2367a984708SDavid Chisnall{
2377a984708SDavid Chisnall    __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
238b2c7081bSDimitry Andric    size_t __sz = _Size;
239b2c7081bSDimitry Andric    for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
240b2c7081bSDimitry Andric        if ( __sz < __bits_per_word)
241b2c7081bSDimitry Andric            __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
242b2c7081bSDimitry Andric        else
2437a984708SDavid Chisnall            __t[__i] = static_cast<__storage_type>(__v);
244b2c7081bSDimitry Andric
2457a984708SDavid Chisnall    _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
2467a984708SDavid Chisnall    _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
2477a984708SDavid Chisnall               __storage_type(0));
2487a984708SDavid Chisnall}
2497a984708SDavid Chisnall
2507a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2517a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2527a984708SDavid Chisnallvoid
25394e3ee44SDavid Chisnall__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
2547a984708SDavid Chisnall{
2557a984708SDavid Chisnall    __first_[0] = __v;
256b2c7081bSDimitry Andric    if (_Size < __bits_per_word)
257b2c7081bSDimitry Andric        __first_[0] &= ( 1ULL << _Size ) - 1;
258b2c7081bSDimitry Andric
2597a984708SDavid Chisnall    _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
2607a984708SDavid Chisnall}
2617a984708SDavid Chisnall
262540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
263936e9439SDimitry Andric
2647a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2659729cf09SDimitry Andricinline
266936e9439SDimitry Andric_LIBCPP_CONSTEXPR
2677a984708SDavid Chisnall__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
268540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
269d72607e9SDimitry Andric#if __SIZEOF_SIZE_T__ == 8
270936e9439SDimitry Andric    : __first_{__v}
271d72607e9SDimitry Andric#elif __SIZEOF_SIZE_T__ == 4
272b2c7081bSDimitry Andric    : __first_{static_cast<__storage_type>(__v),
273b2c7081bSDimitry Andric                _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
274b2c7081bSDimitry Andric                : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
2751bf9f7c1SDimitry Andric#else
2761bf9f7c1SDimitry Andric#error This constructor has not been ported to this platform
2771bf9f7c1SDimitry Andric#endif
278936e9439SDimitry Andric#endif
2797a984708SDavid Chisnall{
280540d2a8bSDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2817a984708SDavid Chisnall    __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
282936e9439SDimitry Andric#endif
2837a984708SDavid Chisnall}
2847a984708SDavid Chisnall
2857a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2869729cf09SDimitry Andricinline
2877a984708SDavid Chisnallvoid
2887a984708SDavid Chisnall__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
2897a984708SDavid Chisnall{
2907a984708SDavid Chisnall    for (size_type __i = 0; __i < _N_words; ++__i)
2917a984708SDavid Chisnall        __first_[__i] &= __v.__first_[__i];
2927a984708SDavid Chisnall}
2937a984708SDavid Chisnall
2947a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
2959729cf09SDimitry Andricinline
2967a984708SDavid Chisnallvoid
2977a984708SDavid Chisnall__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
2987a984708SDavid Chisnall{
2997a984708SDavid Chisnall    for (size_type __i = 0; __i < _N_words; ++__i)
3007a984708SDavid Chisnall        __first_[__i] |= __v.__first_[__i];
3017a984708SDavid Chisnall}
3027a984708SDavid Chisnall
3037a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3049729cf09SDimitry Andricinline
3057a984708SDavid Chisnallvoid
3067a984708SDavid Chisnall__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
3077a984708SDavid Chisnall{
3087a984708SDavid Chisnall    for (size_type __i = 0; __i < _N_words; ++__i)
3097a984708SDavid Chisnall        __first_[__i] ^= __v.__first_[__i];
3107a984708SDavid Chisnall}
3117a984708SDavid Chisnall
3127a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3137a984708SDavid Chisnallvoid
3147a984708SDavid Chisnall__bitset<_N_words, _Size>::flip() _NOEXCEPT
3157a984708SDavid Chisnall{
3167a984708SDavid Chisnall    // do middle whole words
3177a984708SDavid Chisnall    size_type __n = _Size;
3187a984708SDavid Chisnall    __storage_pointer __p = __first_;
3197a984708SDavid Chisnall    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3207a984708SDavid Chisnall        *__p = ~*__p;
3217a984708SDavid Chisnall    // do last partial word
3227a984708SDavid Chisnall    if (__n > 0)
3237a984708SDavid Chisnall    {
3247a984708SDavid Chisnall        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3257a984708SDavid Chisnall        __storage_type __b = *__p & __m;
3267a984708SDavid Chisnall        *__p &= ~__m;
3277a984708SDavid Chisnall        *__p |= ~__b & __m;
3287a984708SDavid Chisnall    }
3297a984708SDavid Chisnall}
3307a984708SDavid Chisnall
3317a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3327a984708SDavid Chisnallunsigned long
3337a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ulong(false_type) const
3347a984708SDavid Chisnall{
3357a984708SDavid Chisnall    const_iterator __e = __make_iter(_Size);
3367a984708SDavid Chisnall    const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
3377a984708SDavid Chisnall    if (__i != __e)
338aed8d94eSDimitry Andric        __throw_overflow_error("bitset to_ulong overflow error");
339aed8d94eSDimitry Andric
3407a984708SDavid Chisnall    return __first_[0];
3417a984708SDavid Chisnall}
3427a984708SDavid Chisnall
3437a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3449729cf09SDimitry Andricinline
3457a984708SDavid Chisnallunsigned long
3467a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ulong(true_type) const
3477a984708SDavid Chisnall{
3487a984708SDavid Chisnall    return __first_[0];
3497a984708SDavid Chisnall}
3507a984708SDavid Chisnall
3517a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3527a984708SDavid Chisnallunsigned long long
3537a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ullong(false_type) const
3547a984708SDavid Chisnall{
3557a984708SDavid Chisnall    const_iterator __e = __make_iter(_Size);
3567a984708SDavid Chisnall    const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
3577a984708SDavid Chisnall    if (__i != __e)
358aed8d94eSDimitry Andric        __throw_overflow_error("bitset to_ullong overflow error");
359aed8d94eSDimitry Andric
3607a984708SDavid Chisnall    return to_ullong(true_type());
3617a984708SDavid Chisnall}
3627a984708SDavid Chisnall
3637a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3649729cf09SDimitry Andricinline
3657a984708SDavid Chisnallunsigned long long
3667a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ullong(true_type) const
3677a984708SDavid Chisnall{
3687a984708SDavid Chisnall    return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
3697a984708SDavid Chisnall}
3707a984708SDavid Chisnall
3717a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3729729cf09SDimitry Andricinline
3737a984708SDavid Chisnallunsigned long long
3747a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
3757a984708SDavid Chisnall{
3767a984708SDavid Chisnall    return __first_[0];
3777a984708SDavid Chisnall}
3787a984708SDavid Chisnall
3797a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3807a984708SDavid Chisnallunsigned long long
3817a984708SDavid Chisnall__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
3827a984708SDavid Chisnall{
3837a984708SDavid Chisnall    unsigned long long __r = __first_[0];
3847a984708SDavid Chisnall    for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
3857a984708SDavid Chisnall        __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
3867a984708SDavid Chisnall    return __r;
3877a984708SDavid Chisnall}
3887a984708SDavid Chisnall
3897a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
3907a984708SDavid Chisnallbool
3917a984708SDavid Chisnall__bitset<_N_words, _Size>::all() const _NOEXCEPT
3927a984708SDavid Chisnall{
3937a984708SDavid Chisnall    // do middle whole words
3947a984708SDavid Chisnall    size_type __n = _Size;
3957a984708SDavid Chisnall    __const_storage_pointer __p = __first_;
3967a984708SDavid Chisnall    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3977a984708SDavid Chisnall        if (~*__p)
3987a984708SDavid Chisnall            return false;
3997a984708SDavid Chisnall    // do last partial word
4007a984708SDavid Chisnall    if (__n > 0)
4017a984708SDavid Chisnall    {
4027a984708SDavid Chisnall        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
4037a984708SDavid Chisnall        if (~*__p & __m)
4047a984708SDavid Chisnall            return false;
4057a984708SDavid Chisnall    }
4067a984708SDavid Chisnall    return true;
4077a984708SDavid Chisnall}
4087a984708SDavid Chisnall
4097a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
4107a984708SDavid Chisnallbool
4117a984708SDavid Chisnall__bitset<_N_words, _Size>::any() const _NOEXCEPT
4127a984708SDavid Chisnall{
4137a984708SDavid Chisnall    // do middle whole words
4147a984708SDavid Chisnall    size_type __n = _Size;
4157a984708SDavid Chisnall    __const_storage_pointer __p = __first_;
4167a984708SDavid Chisnall    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
4177a984708SDavid Chisnall        if (*__p)
4187a984708SDavid Chisnall            return true;
4197a984708SDavid Chisnall    // do last partial word
4207a984708SDavid Chisnall    if (__n > 0)
4217a984708SDavid Chisnall    {
4227a984708SDavid Chisnall        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
4237a984708SDavid Chisnall        if (*__p & __m)
4247a984708SDavid Chisnall            return true;
4257a984708SDavid Chisnall    }
4267a984708SDavid Chisnall    return false;
4277a984708SDavid Chisnall}
4287a984708SDavid Chisnall
4297a984708SDavid Chisnalltemplate <size_t _N_words, size_t _Size>
4309729cf09SDimitry Andricinline
4317a984708SDavid Chisnallsize_t
4327a984708SDavid Chisnall__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
4337a984708SDavid Chisnall{
4347a984708SDavid Chisnall    size_t __h = 0;
4357a984708SDavid Chisnall    for (size_type __i = 0; __i < _N_words; ++__i)
4367a984708SDavid Chisnall        __h ^= __first_[__i];
4377a984708SDavid Chisnall    return __h;
4387a984708SDavid Chisnall}
4397a984708SDavid Chisnall
4407a984708SDavid Chisnalltemplate <size_t _Size>
4417a984708SDavid Chisnallclass __bitset<1, _Size>
4427a984708SDavid Chisnall{
4437a984708SDavid Chisnallpublic:
4447a984708SDavid Chisnall    typedef ptrdiff_t              difference_type;
4457a984708SDavid Chisnall    typedef size_t                 size_type;
446936e9439SDimitry Andric    typedef size_type              __storage_type;
4477a984708SDavid Chisnallprotected:
4487a984708SDavid Chisnall    typedef __bitset __self;
4497a984708SDavid Chisnall    typedef       __storage_type*  __storage_pointer;
4507a984708SDavid Chisnall    typedef const __storage_type*  __const_storage_pointer;
4517a984708SDavid Chisnall    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
4527a984708SDavid Chisnall
4537a984708SDavid Chisnall    friend class __bit_reference<__bitset>;
4547a984708SDavid Chisnall    friend class __bit_const_reference<__bitset>;
4557a984708SDavid Chisnall    friend class __bit_iterator<__bitset, false>;
4567a984708SDavid Chisnall    friend class __bit_iterator<__bitset, true>;
457936e9439SDimitry Andric    friend struct __bit_array<__bitset>;
4587a984708SDavid Chisnall
4597a984708SDavid Chisnall    __storage_type __first_;
4607a984708SDavid Chisnall
4617a984708SDavid Chisnall    typedef __bit_reference<__bitset>                  reference;
4627a984708SDavid Chisnall    typedef __bit_const_reference<__bitset>            const_reference;
4637a984708SDavid Chisnall    typedef __bit_iterator<__bitset, false>            iterator;
4647a984708SDavid Chisnall    typedef __bit_iterator<__bitset, true>             const_iterator;
4657a984708SDavid Chisnall
4669729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
467936e9439SDimitry Andric    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
4689729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
469936e9439SDimitry Andric    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
4707a984708SDavid Chisnall
4717a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
4727a984708SDavid Chisnall        {return reference(&__first_, __storage_type(1) << __pos);}
473936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
4747a984708SDavid Chisnall        {return const_reference(&__first_, __storage_type(1) << __pos);}
4757a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
4767a984708SDavid Chisnall        {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
4777a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
4787a984708SDavid Chisnall        {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
4797a984708SDavid Chisnall
4809729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4817a984708SDavid Chisnall    void operator&=(const __bitset& __v) _NOEXCEPT;
4829729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4837a984708SDavid Chisnall    void operator|=(const __bitset& __v) _NOEXCEPT;
4849729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4857a984708SDavid Chisnall    void operator^=(const __bitset& __v) _NOEXCEPT;
4867a984708SDavid Chisnall
4879729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4887a984708SDavid Chisnall    void flip() _NOEXCEPT;
4897a984708SDavid Chisnall
4909729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4917a984708SDavid Chisnall    unsigned long to_ulong() const;
4929729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4937a984708SDavid Chisnall    unsigned long long to_ullong() const;
4947a984708SDavid Chisnall
4959729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4967a984708SDavid Chisnall    bool all() const _NOEXCEPT;
4979729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4987a984708SDavid Chisnall    bool any() const _NOEXCEPT;
4997a984708SDavid Chisnall
5009729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5017a984708SDavid Chisnall    size_t __hash_code() const _NOEXCEPT;
5027a984708SDavid Chisnall};
5037a984708SDavid Chisnall
5047a984708SDavid Chisnalltemplate <size_t _Size>
5059729cf09SDimitry Andricinline
506936e9439SDimitry Andric_LIBCPP_CONSTEXPR
5077a984708SDavid Chisnall__bitset<1, _Size>::__bitset() _NOEXCEPT
5087a984708SDavid Chisnall    : __first_(0)
5097a984708SDavid Chisnall{
5107a984708SDavid Chisnall}
5117a984708SDavid Chisnall
5127a984708SDavid Chisnalltemplate <size_t _Size>
5139729cf09SDimitry Andricinline
514936e9439SDimitry Andric_LIBCPP_CONSTEXPR
5157a984708SDavid Chisnall__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
516b2c7081bSDimitry Andric    : __first_(
517b2c7081bSDimitry Andric        _Size == __bits_per_word ? static_cast<__storage_type>(__v)
518b2c7081bSDimitry Andric                                 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
519b2c7081bSDimitry Andric    )
5207a984708SDavid Chisnall{
5217a984708SDavid Chisnall}
5227a984708SDavid Chisnall
5237a984708SDavid Chisnalltemplate <size_t _Size>
5249729cf09SDimitry Andricinline
5257a984708SDavid Chisnallvoid
5267a984708SDavid Chisnall__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
5277a984708SDavid Chisnall{
5287a984708SDavid Chisnall    __first_ &= __v.__first_;
5297a984708SDavid Chisnall}
5307a984708SDavid Chisnall
5317a984708SDavid Chisnalltemplate <size_t _Size>
5329729cf09SDimitry Andricinline
5337a984708SDavid Chisnallvoid
5347a984708SDavid Chisnall__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
5357a984708SDavid Chisnall{
5367a984708SDavid Chisnall    __first_ |= __v.__first_;
5377a984708SDavid Chisnall}
5387a984708SDavid Chisnall
5397a984708SDavid Chisnalltemplate <size_t _Size>
5409729cf09SDimitry Andricinline
5417a984708SDavid Chisnallvoid
5427a984708SDavid Chisnall__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
5437a984708SDavid Chisnall{
5447a984708SDavid Chisnall    __first_ ^= __v.__first_;
5457a984708SDavid Chisnall}
5467a984708SDavid Chisnall
5477a984708SDavid Chisnalltemplate <size_t _Size>
5489729cf09SDimitry Andricinline
5497a984708SDavid Chisnallvoid
5507a984708SDavid Chisnall__bitset<1, _Size>::flip() _NOEXCEPT
5517a984708SDavid Chisnall{
5527a984708SDavid Chisnall    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5537a984708SDavid Chisnall    __first_ = ~__first_;
5547a984708SDavid Chisnall    __first_ &= __m;
5557a984708SDavid Chisnall}
5567a984708SDavid Chisnall
5577a984708SDavid Chisnalltemplate <size_t _Size>
5589729cf09SDimitry Andricinline
5597a984708SDavid Chisnallunsigned long
5607a984708SDavid Chisnall__bitset<1, _Size>::to_ulong() const
5617a984708SDavid Chisnall{
5627a984708SDavid Chisnall    return __first_;
5637a984708SDavid Chisnall}
5647a984708SDavid Chisnall
5657a984708SDavid Chisnalltemplate <size_t _Size>
5669729cf09SDimitry Andricinline
5677a984708SDavid Chisnallunsigned long long
5687a984708SDavid Chisnall__bitset<1, _Size>::to_ullong() const
5697a984708SDavid Chisnall{
5707a984708SDavid Chisnall    return __first_;
5717a984708SDavid Chisnall}
5727a984708SDavid Chisnall
5737a984708SDavid Chisnalltemplate <size_t _Size>
5749729cf09SDimitry Andricinline
5757a984708SDavid Chisnallbool
5767a984708SDavid Chisnall__bitset<1, _Size>::all() const _NOEXCEPT
5777a984708SDavid Chisnall{
5787a984708SDavid Chisnall    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5797a984708SDavid Chisnall    return !(~__first_ & __m);
5807a984708SDavid Chisnall}
5817a984708SDavid Chisnall
5827a984708SDavid Chisnalltemplate <size_t _Size>
5839729cf09SDimitry Andricinline
5847a984708SDavid Chisnallbool
5857a984708SDavid Chisnall__bitset<1, _Size>::any() const _NOEXCEPT
5867a984708SDavid Chisnall{
5877a984708SDavid Chisnall    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5887a984708SDavid Chisnall    return __first_ & __m;
5897a984708SDavid Chisnall}
5907a984708SDavid Chisnall
5917a984708SDavid Chisnalltemplate <size_t _Size>
5929729cf09SDimitry Andricinline
5937a984708SDavid Chisnallsize_t
5947a984708SDavid Chisnall__bitset<1, _Size>::__hash_code() const _NOEXCEPT
5957a984708SDavid Chisnall{
5967a984708SDavid Chisnall    return __first_;
5977a984708SDavid Chisnall}
5987a984708SDavid Chisnall
5997a984708SDavid Chisnalltemplate <>
6007a984708SDavid Chisnallclass __bitset<0, 0>
6017a984708SDavid Chisnall{
6027a984708SDavid Chisnallpublic:
6037a984708SDavid Chisnall    typedef ptrdiff_t              difference_type;
6047a984708SDavid Chisnall    typedef size_t                 size_type;
605936e9439SDimitry Andric    typedef size_type              __storage_type;
6067a984708SDavid Chisnallprotected:
6077a984708SDavid Chisnall    typedef __bitset __self;
6087a984708SDavid Chisnall    typedef       __storage_type*  __storage_pointer;
6097a984708SDavid Chisnall    typedef const __storage_type*  __const_storage_pointer;
6107a984708SDavid Chisnall    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
6117a984708SDavid Chisnall
6127a984708SDavid Chisnall    friend class __bit_reference<__bitset>;
6137a984708SDavid Chisnall    friend class __bit_const_reference<__bitset>;
6147a984708SDavid Chisnall    friend class __bit_iterator<__bitset, false>;
6157a984708SDavid Chisnall    friend class __bit_iterator<__bitset, true>;
61694e3ee44SDavid Chisnall    friend struct __bit_array<__bitset>;
6177a984708SDavid Chisnall
6187a984708SDavid Chisnall    typedef __bit_reference<__bitset>                  reference;
6197a984708SDavid Chisnall    typedef __bit_const_reference<__bitset>            const_reference;
6207a984708SDavid Chisnall    typedef __bit_iterator<__bitset, false>            iterator;
6217a984708SDavid Chisnall    typedef __bit_iterator<__bitset, true>             const_iterator;
6227a984708SDavid Chisnall
6239729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
624936e9439SDimitry Andric    _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
6259729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
626936e9439SDimitry Andric    explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
6277a984708SDavid Chisnall
6287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
6297a984708SDavid Chisnall        {return reference(0, 1);}
630936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
6317a984708SDavid Chisnall        {return const_reference(0, 1);}
63294e3ee44SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
6337a984708SDavid Chisnall        {return iterator(0, 0);}
63494e3ee44SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
6357a984708SDavid Chisnall        {return const_iterator(0, 0);}
6367a984708SDavid Chisnall
6377a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
6387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
6397a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
6407a984708SDavid Chisnall
6417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
6427a984708SDavid Chisnall
6437a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
6447a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
6457a984708SDavid Chisnall
6467a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
6477a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
6487a984708SDavid Chisnall
6497a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
6507a984708SDavid Chisnall};
6517a984708SDavid Chisnall
6529729cf09SDimitry Andricinline
653936e9439SDimitry Andric_LIBCPP_CONSTEXPR
6547a984708SDavid Chisnall__bitset<0, 0>::__bitset() _NOEXCEPT
6557a984708SDavid Chisnall{
6567a984708SDavid Chisnall}
6577a984708SDavid Chisnall
6589729cf09SDimitry Andricinline
659936e9439SDimitry Andric_LIBCPP_CONSTEXPR
6607a984708SDavid Chisnall__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
6617a984708SDavid Chisnall{
6627a984708SDavid Chisnall}
6637a984708SDavid Chisnall
664aed8d94eSDimitry Andrictemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
6657c82a1ecSDimitry Andrictemplate <size_t _Size> struct hash<bitset<_Size> >;
6667a984708SDavid Chisnall
6677a984708SDavid Chisnalltemplate <size_t _Size>
668aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset
6697a984708SDavid Chisnall    : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
6707a984708SDavid Chisnall{
6711bf9f7c1SDimitry Andricpublic:
6727a984708SDavid Chisnall    static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
6737a984708SDavid Chisnall    typedef __bitset<__n_words, _Size> base;
6747a984708SDavid Chisnall
6757a984708SDavid Chisnallpublic:
6767a984708SDavid Chisnall    typedef typename base::reference       reference;
6777a984708SDavid Chisnall    typedef typename base::const_reference const_reference;
6787a984708SDavid Chisnall
6797a984708SDavid Chisnall    // 23.3.5.1 constructors:
680936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
681936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
682936e9439SDimitry Andric        bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
6837a984708SDavid Chisnall    template<class _CharT>
6847a984708SDavid Chisnall        explicit bitset(const _CharT* __str,
6857a984708SDavid Chisnall                        typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
6867a984708SDavid Chisnall                        _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
6877a984708SDavid Chisnall    template<class _CharT, class _Traits, class _Allocator>
6887a984708SDavid Chisnall        explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
6897a984708SDavid Chisnall                        typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
6907a984708SDavid Chisnall                        typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
6917a984708SDavid Chisnall                                (basic_string<_CharT,_Traits,_Allocator>::npos),
6927a984708SDavid Chisnall                        _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
6937a984708SDavid Chisnall
6947a984708SDavid Chisnall    // 23.3.5.2 bitset operations:
6959729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6967a984708SDavid Chisnall    bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
6979729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6987a984708SDavid Chisnall    bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
6999729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7007a984708SDavid Chisnall    bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
7017a984708SDavid Chisnall    bitset& operator<<=(size_t __pos) _NOEXCEPT;
7027a984708SDavid Chisnall    bitset& operator>>=(size_t __pos) _NOEXCEPT;
7039729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7047a984708SDavid Chisnall    bitset& set() _NOEXCEPT;
7057a984708SDavid Chisnall    bitset& set(size_t __pos, bool __val = true);
7069729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7077a984708SDavid Chisnall    bitset& reset() _NOEXCEPT;
7087a984708SDavid Chisnall    bitset& reset(size_t __pos);
7099729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7107a984708SDavid Chisnall    bitset  operator~() const _NOEXCEPT;
7119729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7127a984708SDavid Chisnall    bitset& flip() _NOEXCEPT;
7137a984708SDavid Chisnall    bitset& flip(size_t __pos);
7147a984708SDavid Chisnall
7157a984708SDavid Chisnall    // element access:
716936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
717936e9439SDimitry Andric                              const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
7187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY       reference operator[](size_t __p)       {return base::__make_ref(__p);}
7199729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7207a984708SDavid Chisnall    unsigned long to_ulong() const;
7219729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7227a984708SDavid Chisnall    unsigned long long to_ullong() const;
7237a984708SDavid Chisnall    template <class _CharT, class _Traits, class _Allocator>
7247a984708SDavid Chisnall        basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
7257a984708SDavid Chisnall                                                            _CharT __one = _CharT('1')) const;
7267a984708SDavid Chisnall    template <class _CharT, class _Traits>
7279729cf09SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
7287a984708SDavid Chisnall        basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
7297a984708SDavid Chisnall                                                                    _CharT __one = _CharT('1')) const;
7307a984708SDavid Chisnall    template <class _CharT>
7319729cf09SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
7327a984708SDavid Chisnall        basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
7337a984708SDavid Chisnall                                                                                _CharT __one = _CharT('1')) const;
7349729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7357a984708SDavid Chisnall    basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
7367a984708SDavid Chisnall                                                                      char __one = '1') const;
7379729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7387a984708SDavid Chisnall    size_t count() const _NOEXCEPT;
739936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
7409729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7417a984708SDavid Chisnall    bool operator==(const bitset& __rhs) const _NOEXCEPT;
7429729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7437a984708SDavid Chisnall    bool operator!=(const bitset& __rhs) const _NOEXCEPT;
7447a984708SDavid Chisnall    bool test(size_t __pos) const;
7459729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7467a984708SDavid Chisnall    bool all() const _NOEXCEPT;
7479729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7487a984708SDavid Chisnall    bool any() const _NOEXCEPT;
7497a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
7509729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7517a984708SDavid Chisnall    bitset operator<<(size_t __pos) const _NOEXCEPT;
7529729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7537a984708SDavid Chisnall    bitset operator>>(size_t __pos) const _NOEXCEPT;
7547a984708SDavid Chisnall
7557a984708SDavid Chisnallprivate:
7567a984708SDavid Chisnall
7577a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7587a984708SDavid Chisnall    size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
7597a984708SDavid Chisnall
7607a984708SDavid Chisnall    friend struct hash<bitset>;
7617a984708SDavid Chisnall};
7627a984708SDavid Chisnall
7637a984708SDavid Chisnalltemplate <size_t _Size>
7647a984708SDavid Chisnalltemplate<class _CharT>
7657a984708SDavid Chisnallbitset<_Size>::bitset(const _CharT* __str,
7667a984708SDavid Chisnall                      typename basic_string<_CharT>::size_type __n,
7677a984708SDavid Chisnall                      _CharT __zero, _CharT __one)
7687a984708SDavid Chisnall{
7697a984708SDavid Chisnall    size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
7707a984708SDavid Chisnall    for (size_t __i = 0; __i < __rlen; ++__i)
7717a984708SDavid Chisnall        if (__str[__i] != __zero && __str[__i] != __one)
772aed8d94eSDimitry Andric            __throw_invalid_argument("bitset string ctor has invalid argument");
773aed8d94eSDimitry Andric
77494e3ee44SDavid Chisnall    size_t _Mp = _VSTD::min(__rlen, _Size);
7757a984708SDavid Chisnall    size_t __i = 0;
77694e3ee44SDavid Chisnall    for (; __i < _Mp; ++__i)
7777a984708SDavid Chisnall    {
77894e3ee44SDavid Chisnall        _CharT __c = __str[_Mp - 1 - __i];
7797a984708SDavid Chisnall        if (__c == __zero)
7807a984708SDavid Chisnall            (*this)[__i] = false;
7817a984708SDavid Chisnall        else
7827a984708SDavid Chisnall            (*this)[__i] = true;
7837a984708SDavid Chisnall    }
7847a984708SDavid Chisnall    _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
7857a984708SDavid Chisnall}
7867a984708SDavid Chisnall
7877a984708SDavid Chisnalltemplate <size_t _Size>
7887a984708SDavid Chisnalltemplate<class _CharT, class _Traits, class _Allocator>
7897a984708SDavid Chisnallbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
7907a984708SDavid Chisnall       typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
7917a984708SDavid Chisnall       typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
7927a984708SDavid Chisnall       _CharT __zero, _CharT __one)
7937a984708SDavid Chisnall{
7947a984708SDavid Chisnall    if (__pos > __str.size())
795aed8d94eSDimitry Andric        __throw_out_of_range("bitset string pos out of range");
796aed8d94eSDimitry Andric
7977a984708SDavid Chisnall    size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
7987a984708SDavid Chisnall    for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
7997a984708SDavid Chisnall        if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
800aed8d94eSDimitry Andric            __throw_invalid_argument("bitset string ctor has invalid argument");
801aed8d94eSDimitry Andric
80294e3ee44SDavid Chisnall    size_t _Mp = _VSTD::min(__rlen, _Size);
8037a984708SDavid Chisnall    size_t __i = 0;
80494e3ee44SDavid Chisnall    for (; __i < _Mp; ++__i)
8057a984708SDavid Chisnall    {
80694e3ee44SDavid Chisnall        _CharT __c = __str[__pos + _Mp - 1 - __i];
8077a984708SDavid Chisnall        if (_Traits::eq(__c, __zero))
8087a984708SDavid Chisnall            (*this)[__i] = false;
8097a984708SDavid Chisnall        else
8107a984708SDavid Chisnall            (*this)[__i] = true;
8117a984708SDavid Chisnall    }
8127a984708SDavid Chisnall    _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
8137a984708SDavid Chisnall}
8147a984708SDavid Chisnall
8157a984708SDavid Chisnalltemplate <size_t _Size>
8169729cf09SDimitry Andricinline
8177a984708SDavid Chisnallbitset<_Size>&
8187a984708SDavid Chisnallbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
8197a984708SDavid Chisnall{
8207a984708SDavid Chisnall    base::operator&=(__rhs);
8217a984708SDavid Chisnall    return *this;
8227a984708SDavid Chisnall}
8237a984708SDavid Chisnall
8247a984708SDavid Chisnalltemplate <size_t _Size>
8259729cf09SDimitry Andricinline
8267a984708SDavid Chisnallbitset<_Size>&
8277a984708SDavid Chisnallbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
8287a984708SDavid Chisnall{
8297a984708SDavid Chisnall    base::operator|=(__rhs);
8307a984708SDavid Chisnall    return *this;
8317a984708SDavid Chisnall}
8327a984708SDavid Chisnall
8337a984708SDavid Chisnalltemplate <size_t _Size>
8349729cf09SDimitry Andricinline
8357a984708SDavid Chisnallbitset<_Size>&
8367a984708SDavid Chisnallbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
8377a984708SDavid Chisnall{
8387a984708SDavid Chisnall    base::operator^=(__rhs);
8397a984708SDavid Chisnall    return *this;
8407a984708SDavid Chisnall}
8417a984708SDavid Chisnall
8427a984708SDavid Chisnalltemplate <size_t _Size>
8437a984708SDavid Chisnallbitset<_Size>&
8447a984708SDavid Chisnallbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
8457a984708SDavid Chisnall{
8467a984708SDavid Chisnall    __pos = _VSTD::min(__pos, _Size);
8477a984708SDavid Chisnall    _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
8487a984708SDavid Chisnall    _VSTD::fill_n(base::__make_iter(0), __pos, false);
8497a984708SDavid Chisnall    return *this;
8507a984708SDavid Chisnall}
8517a984708SDavid Chisnall
8527a984708SDavid Chisnalltemplate <size_t _Size>
8537a984708SDavid Chisnallbitset<_Size>&
8547a984708SDavid Chisnallbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
8557a984708SDavid Chisnall{
8567a984708SDavid Chisnall    __pos = _VSTD::min(__pos, _Size);
8577a984708SDavid Chisnall    _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
8587a984708SDavid Chisnall    _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
8597a984708SDavid Chisnall    return *this;
8607a984708SDavid Chisnall}
8617a984708SDavid Chisnall
8627a984708SDavid Chisnalltemplate <size_t _Size>
8639729cf09SDimitry Andricinline
8647a984708SDavid Chisnallbitset<_Size>&
8657a984708SDavid Chisnallbitset<_Size>::set() _NOEXCEPT
8667a984708SDavid Chisnall{
8677a984708SDavid Chisnall    _VSTD::fill_n(base::__make_iter(0), _Size, true);
8687a984708SDavid Chisnall    return *this;
8697a984708SDavid Chisnall}
8707a984708SDavid Chisnall
8717a984708SDavid Chisnalltemplate <size_t _Size>
8727a984708SDavid Chisnallbitset<_Size>&
8737a984708SDavid Chisnallbitset<_Size>::set(size_t __pos, bool __val)
8747a984708SDavid Chisnall{
8757a984708SDavid Chisnall    if (__pos >= _Size)
876aed8d94eSDimitry Andric        __throw_out_of_range("bitset set argument out of range");
877aed8d94eSDimitry Andric
8787a984708SDavid Chisnall    (*this)[__pos] = __val;
8797a984708SDavid Chisnall    return *this;
8807a984708SDavid Chisnall}
8817a984708SDavid Chisnall
8827a984708SDavid Chisnalltemplate <size_t _Size>
8839729cf09SDimitry Andricinline
8847a984708SDavid Chisnallbitset<_Size>&
8857a984708SDavid Chisnallbitset<_Size>::reset() _NOEXCEPT
8867a984708SDavid Chisnall{
8877a984708SDavid Chisnall    _VSTD::fill_n(base::__make_iter(0), _Size, false);
8887a984708SDavid Chisnall    return *this;
8897a984708SDavid Chisnall}
8907a984708SDavid Chisnall
8917a984708SDavid Chisnalltemplate <size_t _Size>
8927a984708SDavid Chisnallbitset<_Size>&
8937a984708SDavid Chisnallbitset<_Size>::reset(size_t __pos)
8947a984708SDavid Chisnall{
8957a984708SDavid Chisnall    if (__pos >= _Size)
896aed8d94eSDimitry Andric        __throw_out_of_range("bitset reset argument out of range");
897aed8d94eSDimitry Andric
8987a984708SDavid Chisnall    (*this)[__pos] = false;
8997a984708SDavid Chisnall    return *this;
9007a984708SDavid Chisnall}
9017a984708SDavid Chisnall
9027a984708SDavid Chisnalltemplate <size_t _Size>
9039729cf09SDimitry Andricinline
9047a984708SDavid Chisnallbitset<_Size>
9057a984708SDavid Chisnallbitset<_Size>::operator~() const _NOEXCEPT
9067a984708SDavid Chisnall{
9077a984708SDavid Chisnall    bitset __x(*this);
9087a984708SDavid Chisnall    __x.flip();
9097a984708SDavid Chisnall    return __x;
9107a984708SDavid Chisnall}
9117a984708SDavid Chisnall
9127a984708SDavid Chisnalltemplate <size_t _Size>
9139729cf09SDimitry Andricinline
9147a984708SDavid Chisnallbitset<_Size>&
9157a984708SDavid Chisnallbitset<_Size>::flip() _NOEXCEPT
9167a984708SDavid Chisnall{
9177a984708SDavid Chisnall    base::flip();
9187a984708SDavid Chisnall    return *this;
9197a984708SDavid Chisnall}
9207a984708SDavid Chisnall
9217a984708SDavid Chisnalltemplate <size_t _Size>
9227a984708SDavid Chisnallbitset<_Size>&
9237a984708SDavid Chisnallbitset<_Size>::flip(size_t __pos)
9247a984708SDavid Chisnall{
9257a984708SDavid Chisnall    if (__pos >= _Size)
926aed8d94eSDimitry Andric        __throw_out_of_range("bitset flip argument out of range");
927aed8d94eSDimitry Andric
9287a984708SDavid Chisnall    reference r = base::__make_ref(__pos);
9297a984708SDavid Chisnall    r = ~r;
9307a984708SDavid Chisnall    return *this;
9317a984708SDavid Chisnall}
9327a984708SDavid Chisnall
9337a984708SDavid Chisnalltemplate <size_t _Size>
9349729cf09SDimitry Andricinline
9357a984708SDavid Chisnallunsigned long
9367a984708SDavid Chisnallbitset<_Size>::to_ulong() const
9377a984708SDavid Chisnall{
9387a984708SDavid Chisnall    return base::to_ulong();
9397a984708SDavid Chisnall}
9407a984708SDavid Chisnall
9417a984708SDavid Chisnalltemplate <size_t _Size>
9429729cf09SDimitry Andricinline
9437a984708SDavid Chisnallunsigned long long
9447a984708SDavid Chisnallbitset<_Size>::to_ullong() const
9457a984708SDavid Chisnall{
9467a984708SDavid Chisnall    return base::to_ullong();
9477a984708SDavid Chisnall}
9487a984708SDavid Chisnall
9497a984708SDavid Chisnalltemplate <size_t _Size>
9507a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _Allocator>
9517a984708SDavid Chisnallbasic_string<_CharT, _Traits, _Allocator>
9527a984708SDavid Chisnallbitset<_Size>::to_string(_CharT __zero, _CharT __one) const
9537a984708SDavid Chisnall{
9547a984708SDavid Chisnall    basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
9557a984708SDavid Chisnall    for (size_t __i = 0; __i < _Size; ++__i)
9567a984708SDavid Chisnall    {
9577a984708SDavid Chisnall        if ((*this)[__i])
9587a984708SDavid Chisnall            __r[_Size - 1 - __i] = __one;
9597a984708SDavid Chisnall    }
9607a984708SDavid Chisnall    return __r;
9617a984708SDavid Chisnall}
9627a984708SDavid Chisnall
9637a984708SDavid Chisnalltemplate <size_t _Size>
9647a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
9659729cf09SDimitry Andricinline
9667a984708SDavid Chisnallbasic_string<_CharT, _Traits, allocator<_CharT> >
9677a984708SDavid Chisnallbitset<_Size>::to_string(_CharT __zero, _CharT __one) const
9687a984708SDavid Chisnall{
9697a984708SDavid Chisnall    return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
9707a984708SDavid Chisnall}
9717a984708SDavid Chisnall
9727a984708SDavid Chisnalltemplate <size_t _Size>
9737a984708SDavid Chisnalltemplate <class _CharT>
9749729cf09SDimitry Andricinline
9757a984708SDavid Chisnallbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
9767a984708SDavid Chisnallbitset<_Size>::to_string(_CharT __zero, _CharT __one) const
9777a984708SDavid Chisnall{
9787a984708SDavid Chisnall    return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
9797a984708SDavid Chisnall}
9807a984708SDavid Chisnall
9817a984708SDavid Chisnalltemplate <size_t _Size>
9829729cf09SDimitry Andricinline
9837a984708SDavid Chisnallbasic_string<char, char_traits<char>, allocator<char> >
9847a984708SDavid Chisnallbitset<_Size>::to_string(char __zero, char __one) const
9857a984708SDavid Chisnall{
9867a984708SDavid Chisnall    return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
9877a984708SDavid Chisnall}
9887a984708SDavid Chisnall
9897a984708SDavid Chisnalltemplate <size_t _Size>
9909729cf09SDimitry Andricinline
9917a984708SDavid Chisnallsize_t
9927a984708SDavid Chisnallbitset<_Size>::count() const _NOEXCEPT
9937a984708SDavid Chisnall{
994*b5893f02SDimitry Andric    return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size));
9957a984708SDavid Chisnall}
9967a984708SDavid Chisnall
9977a984708SDavid Chisnalltemplate <size_t _Size>
9989729cf09SDimitry Andricinline
9997a984708SDavid Chisnallbool
10007a984708SDavid Chisnallbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
10017a984708SDavid Chisnall{
10027a984708SDavid Chisnall    return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
10037a984708SDavid Chisnall}
10047a984708SDavid Chisnall
10057a984708SDavid Chisnalltemplate <size_t _Size>
10069729cf09SDimitry Andricinline
10077a984708SDavid Chisnallbool
10087a984708SDavid Chisnallbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
10097a984708SDavid Chisnall{
10107a984708SDavid Chisnall    return !(*this == __rhs);
10117a984708SDavid Chisnall}
10127a984708SDavid Chisnall
10137a984708SDavid Chisnalltemplate <size_t _Size>
10147a984708SDavid Chisnallbool
10157a984708SDavid Chisnallbitset<_Size>::test(size_t __pos) const
10167a984708SDavid Chisnall{
10177a984708SDavid Chisnall    if (__pos >= _Size)
1018aed8d94eSDimitry Andric        __throw_out_of_range("bitset test argument out of range");
1019aed8d94eSDimitry Andric
10207a984708SDavid Chisnall    return (*this)[__pos];
10217a984708SDavid Chisnall}
10227a984708SDavid Chisnall
10237a984708SDavid Chisnalltemplate <size_t _Size>
10249729cf09SDimitry Andricinline
10257a984708SDavid Chisnallbool
10267a984708SDavid Chisnallbitset<_Size>::all() const _NOEXCEPT
10277a984708SDavid Chisnall{
10287a984708SDavid Chisnall    return base::all();
10297a984708SDavid Chisnall}
10307a984708SDavid Chisnall
10317a984708SDavid Chisnalltemplate <size_t _Size>
10329729cf09SDimitry Andricinline
10337a984708SDavid Chisnallbool
10347a984708SDavid Chisnallbitset<_Size>::any() const _NOEXCEPT
10357a984708SDavid Chisnall{
10367a984708SDavid Chisnall    return base::any();
10377a984708SDavid Chisnall}
10387a984708SDavid Chisnall
10397a984708SDavid Chisnalltemplate <size_t _Size>
10409729cf09SDimitry Andricinline
10417a984708SDavid Chisnallbitset<_Size>
10427a984708SDavid Chisnallbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
10437a984708SDavid Chisnall{
10447a984708SDavid Chisnall    bitset __r = *this;
10457a984708SDavid Chisnall    __r <<= __pos;
10467a984708SDavid Chisnall    return __r;
10477a984708SDavid Chisnall}
10487a984708SDavid Chisnall
10497a984708SDavid Chisnalltemplate <size_t _Size>
10509729cf09SDimitry Andricinline
10517a984708SDavid Chisnallbitset<_Size>
10527a984708SDavid Chisnallbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
10537a984708SDavid Chisnall{
10547a984708SDavid Chisnall    bitset __r = *this;
10557a984708SDavid Chisnall    __r >>= __pos;
10567a984708SDavid Chisnall    return __r;
10577a984708SDavid Chisnall}
10587a984708SDavid Chisnall
10597a984708SDavid Chisnalltemplate <size_t _Size>
10607a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
10617a984708SDavid Chisnallbitset<_Size>
10627a984708SDavid Chisnalloperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
10637a984708SDavid Chisnall{
10647a984708SDavid Chisnall    bitset<_Size> __r = __x;
10657a984708SDavid Chisnall    __r &= __y;
10667a984708SDavid Chisnall    return __r;
10677a984708SDavid Chisnall}
10687a984708SDavid Chisnall
10697a984708SDavid Chisnalltemplate <size_t _Size>
10707a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
10717a984708SDavid Chisnallbitset<_Size>
10727a984708SDavid Chisnalloperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
10737a984708SDavid Chisnall{
10747a984708SDavid Chisnall    bitset<_Size> __r = __x;
10757a984708SDavid Chisnall    __r |= __y;
10767a984708SDavid Chisnall    return __r;
10777a984708SDavid Chisnall}
10787a984708SDavid Chisnall
10797a984708SDavid Chisnalltemplate <size_t _Size>
10807a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
10817a984708SDavid Chisnallbitset<_Size>
10827a984708SDavid Chisnalloperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
10837a984708SDavid Chisnall{
10847a984708SDavid Chisnall    bitset<_Size> __r = __x;
10857a984708SDavid Chisnall    __r ^= __y;
10867a984708SDavid Chisnall    return __r;
10877a984708SDavid Chisnall}
10887a984708SDavid Chisnall
10897a984708SDavid Chisnalltemplate <size_t _Size>
1090aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
10917a984708SDavid Chisnall    : public unary_function<bitset<_Size>, size_t>
10927a984708SDavid Chisnall{
10937a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10947a984708SDavid Chisnall    size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
10957a984708SDavid Chisnall        {return __bs.__hash_code();}
10967a984708SDavid Chisnall};
10977a984708SDavid Chisnall
10987a984708SDavid Chisnalltemplate <class _CharT, class _Traits, size_t _Size>
10997a984708SDavid Chisnallbasic_istream<_CharT, _Traits>&
11007a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
11017a984708SDavid Chisnall
11027a984708SDavid Chisnalltemplate <class _CharT, class _Traits, size_t _Size>
11037a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>&
11047a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
11057a984708SDavid Chisnall
11067a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
11077a984708SDavid Chisnall
1108f9448bf3SDimitry Andric_LIBCPP_POP_MACROS
1109f9448bf3SDimitry Andric
11107a984708SDavid Chisnall#endif  // _LIBCPP_BITSET
1111