2010-05-11 19:42:16 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- bitset ----------------------------------===//
|
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_BITSET
|
|
|
|
#define _LIBCPP_BITSET
|
|
|
|
|
|
|
|
/*
|
|
|
|
bitset synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
class bitset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// bit reference:
|
|
|
|
class reference
|
|
|
|
{
|
|
|
|
friend class bitset;
|
2011-05-27 20:52:28 +00:00
|
|
|
reference() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
public:
|
2011-05-27 20:52:28 +00:00
|
|
|
~reference() noexcept;
|
|
|
|
reference& operator=(bool x) noexcept; // for b[i] = x;
|
|
|
|
reference& operator=(const reference&) noexcept; // for b[i] = b[j];
|
|
|
|
bool operator~() const noexcept; // flips the bit
|
|
|
|
operator bool() const noexcept; // for x = b[i];
|
|
|
|
reference& flip() noexcept; // for b[i].flip();
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 23.3.5.1 constructors:
|
2011-05-27 20:52:28 +00:00
|
|
|
constexpr bitset() noexcept;
|
|
|
|
constexpr bitset(unsigned long long val) noexcept;
|
2010-11-17 21:53:14 +00:00
|
|
|
template <class charT>
|
|
|
|
explicit bitset(const charT* str,
|
|
|
|
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
|
|
|
charT zero = charT('0'), charT one = charT('1'));
|
2010-05-11 19:42:16 +00:00
|
|
|
template<class charT, class traits, class Allocator>
|
|
|
|
explicit bitset(const basic_string<charT,traits,Allocator>& str,
|
|
|
|
typename basic_string<charT,traits,Allocator>::size_type pos = 0,
|
|
|
|
typename basic_string<charT,traits,Allocator>::size_type n =
|
|
|
|
basic_string<charT,traits,Allocator>::npos,
|
|
|
|
charT zero = charT('0'), charT one = charT('1'));
|
|
|
|
|
|
|
|
// 23.3.5.2 bitset operations:
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& operator&=(const bitset& rhs) noexcept;
|
|
|
|
bitset& operator|=(const bitset& rhs) noexcept;
|
|
|
|
bitset& operator^=(const bitset& rhs) noexcept;
|
|
|
|
bitset& operator<<=(size_t pos) noexcept;
|
|
|
|
bitset& operator>>=(size_t pos) noexcept;
|
|
|
|
bitset& set() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset& set(size_t pos, bool val = true);
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& reset() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset& reset(size_t pos);
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset operator~() const noexcept;
|
|
|
|
bitset& flip() noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset& flip(size_t pos);
|
|
|
|
|
|
|
|
// element access:
|
|
|
|
constexpr bool operator[](size_t pos) const; // for b[i];
|
|
|
|
reference operator[](size_t pos); // for b[i];
|
|
|
|
unsigned long to_ulong() const;
|
|
|
|
unsigned long long to_ullong() const;
|
|
|
|
template <class charT, class traits, class Allocator>
|
|
|
|
basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
|
|
|
template <class charT, class traits>
|
|
|
|
basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
|
|
|
template <class charT>
|
|
|
|
basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
|
|
|
basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t count() const noexcept;
|
|
|
|
constexpr size_t size() const noexcept;
|
|
|
|
bool operator==(const bitset& rhs) const noexcept;
|
|
|
|
bool operator!=(const bitset& rhs) const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
bool test(size_t pos) const;
|
2011-05-27 20:52:28 +00:00
|
|
|
bool all() const noexcept;
|
|
|
|
bool any() const noexcept;
|
|
|
|
bool none() const noexcept;
|
|
|
|
bitset operator<<(size_t pos) const noexcept;
|
|
|
|
bitset operator>>(size_t pos) const noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// 23.3.5.3 bitset operators:
|
|
|
|
template <size_t N>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <size_t N>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <size_t N>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <class charT, class traits, size_t N>
|
|
|
|
basic_istream<charT, traits>&
|
|
|
|
operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
|
|
|
|
|
|
|
|
template <class charT, class traits, size_t N>
|
|
|
|
basic_ostream<charT, traits>&
|
|
|
|
operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
|
|
|
|
|
|
|
|
template <size_t N> struct hash<std::bitset<N>>;
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <__bit_reference>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <climits>
|
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <__functional_base>
|
|
|
|
|
2017-05-31 22:07:49 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
|
|
#pragma GCC system_header
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2011-11-29 16:45:27 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2011-07-02 20:33:23 +00:00
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
class __bitset;
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
struct __has_storage_type<__bitset<_N_words, _Size> >
|
|
|
|
{
|
|
|
|
static const bool value = true;
|
|
|
|
};
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
class __bitset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef size_t size_type;
|
2012-05-07 16:50:38 +00:00
|
|
|
typedef size_type __storage_type;
|
2010-05-11 19:42:16 +00:00
|
|
|
protected:
|
|
|
|
typedef __bitset __self;
|
|
|
|
typedef __storage_type* __storage_pointer;
|
|
|
|
typedef const __storage_type* __const_storage_pointer;
|
|
|
|
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
|
|
|
|
|
|
|
|
friend class __bit_reference<__bitset>;
|
|
|
|
friend class __bit_const_reference<__bitset>;
|
|
|
|
friend class __bit_iterator<__bitset, false>;
|
|
|
|
friend class __bit_iterator<__bitset, true>;
|
2012-08-17 17:10:18 +00:00
|
|
|
friend struct __bit_array<__bitset>;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
__storage_type __first_[_N_words];
|
|
|
|
|
|
|
|
typedef __bit_reference<__bitset> reference;
|
|
|
|
typedef __bit_const_reference<__bitset> const_reference;
|
|
|
|
typedef __bit_iterator<__bitset, false> iterator;
|
|
|
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator&=(const __bitset& __v) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator|=(const __bitset& __v) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator^=(const __bitset& __v) _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
void flip() _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
|
|
|
|
{return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
|
|
|
|
{return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
|
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
bool all() const _NOEXCEPT;
|
|
|
|
bool any() const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t __hash_code() const _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
private:
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
2011-05-27 20:52:28 +00:00
|
|
|
void __init(unsigned long long __v, false_type) _NOEXCEPT;
|
2015-12-09 22:32:36 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void __init(unsigned long long __v, true_type) _NOEXCEPT;
|
2017-04-19 01:34:08 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long to_ulong(false_type) const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long to_ulong(true_type) const;
|
|
|
|
unsigned long long to_ullong(false_type) const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long to_ullong(true_type) const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long to_ullong(true_type, false_type) const;
|
|
|
|
unsigned long long to_ullong(true_type, true_type) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2012-07-07 17:04:52 +00:00
|
|
|
: __first_{0}
|
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill_n(__first_, _N_words, __storage_type(0));
|
2012-07-07 17:04:52 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
2012-07-07 17:04:52 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
void
|
2011-12-01 20:21:04 +00:00
|
|
|
__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
|
2017-11-27 22:27:22 +00:00
|
|
|
size_t __sz = _Size;
|
|
|
|
for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
|
|
|
|
if ( __sz < __bits_per_word)
|
2018-08-03 22:36:53 +00:00
|
|
|
__t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
|
2017-11-27 22:27:22 +00:00
|
|
|
else
|
2018-08-03 22:36:53 +00:00
|
|
|
__t[__i] = static_cast<__storage_type>(__v);
|
2017-11-27 22:27:22 +00:00
|
|
|
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
|
|
|
|
_VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
|
2010-05-11 19:42:16 +00:00
|
|
|
__storage_type(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
2011-12-01 20:21:04 +00:00
|
|
|
__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__first_[0] = __v;
|
2017-11-27 22:27:22 +00:00
|
|
|
if (_Size < __bits_per_word)
|
2018-08-03 22:36:53 +00:00
|
|
|
__first_[0] &= ( 1ULL << _Size ) - 1;
|
2017-11-27 22:27:22 +00:00
|
|
|
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 01:34:08 +00:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2012-07-07 17:04:52 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2014-06-04 15:46:56 +00:00
|
|
|
#if __SIZEOF_SIZE_T__ == 8
|
2012-07-07 17:04:52 +00:00
|
|
|
: __first_{__v}
|
2014-06-04 15:46:56 +00:00
|
|
|
#elif __SIZEOF_SIZE_T__ == 4
|
2018-08-03 22:36:53 +00:00
|
|
|
: __first_{static_cast<__storage_type>(__v),
|
|
|
|
_Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
|
|
|
|
: static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
|
2013-03-06 18:16:12 +00:00
|
|
|
#else
|
2013-03-06 17:30:26 +00:00
|
|
|
#error This constructor has not been ported to this platform
|
|
|
|
#endif
|
2012-07-07 17:04:52 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2017-04-19 01:34:08 +00:00
|
|
|
#ifdef _LIBCPP_CXX03_LANG
|
2010-05-11 19:42:16 +00:00
|
|
|
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
|
2012-07-07 17:04:52 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
for (size_type __i = 0; __i < _N_words; ++__i)
|
|
|
|
__first_[__i] &= __v.__first_[__i];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
for (size_type __i = 0; __i < _N_words; ++__i)
|
|
|
|
__first_[__i] |= __v.__first_[__i];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
for (size_type __i = 0; __i < _N_words; ++__i)
|
|
|
|
__first_[__i] ^= __v.__first_[__i];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::flip() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
// do middle whole words
|
|
|
|
size_type __n = _Size;
|
|
|
|
__storage_pointer __p = __first_;
|
|
|
|
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
|
|
|
|
*__p = ~*__p;
|
|
|
|
// do last partial word
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
|
|
|
__storage_type __b = *__p & __m;
|
|
|
|
*__p &= ~__m;
|
|
|
|
*__p |= ~__b & __m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
unsigned long
|
|
|
|
__bitset<_N_words, _Size>::to_ulong(false_type) const
|
|
|
|
{
|
|
|
|
const_iterator __e = __make_iter(_Size);
|
2011-06-30 21:18:19 +00:00
|
|
|
const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
|
2010-05-11 19:42:16 +00:00
|
|
|
if (__i != __e)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_overflow_error("bitset to_ulong overflow error");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
return __first_[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long
|
|
|
|
__bitset<_N_words, _Size>::to_ulong(true_type) const
|
|
|
|
{
|
|
|
|
return __first_[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
unsigned long long
|
|
|
|
__bitset<_N_words, _Size>::to_ullong(false_type) const
|
|
|
|
{
|
|
|
|
const_iterator __e = __make_iter(_Size);
|
2011-06-30 21:18:19 +00:00
|
|
|
const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
|
2010-05-11 19:42:16 +00:00
|
|
|
if (__i != __e)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_overflow_error("bitset to_ullong overflow error");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
return to_ullong(true_type());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long
|
|
|
|
__bitset<_N_words, _Size>::to_ullong(true_type) const
|
|
|
|
{
|
|
|
|
return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long
|
|
|
|
__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
|
|
|
|
{
|
|
|
|
return __first_[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
unsigned long long
|
|
|
|
__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
|
|
|
|
{
|
|
|
|
unsigned long long __r = __first_[0];
|
|
|
|
for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
|
|
|
|
__r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::all() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
// do middle whole words
|
|
|
|
size_type __n = _Size;
|
|
|
|
__const_storage_pointer __p = __first_;
|
|
|
|
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
|
|
|
|
if (~*__p)
|
|
|
|
return false;
|
|
|
|
// do last partial word
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
|
|
|
if (~*__p & __m)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::any() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
// do middle whole words
|
|
|
|
size_type __n = _Size;
|
|
|
|
__const_storage_pointer __p = __first_;
|
|
|
|
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
|
|
|
|
if (*__p)
|
|
|
|
return true;
|
|
|
|
// do last partial word
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
|
|
|
if (*__p & __m)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _N_words, size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
size_t
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
size_t __h = 0;
|
|
|
|
for (size_type __i = 0; __i < _N_words; ++__i)
|
|
|
|
__h ^= __first_[__i];
|
|
|
|
return __h;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
class __bitset<1, _Size>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef size_t size_type;
|
2012-05-07 16:50:38 +00:00
|
|
|
typedef size_type __storage_type;
|
2010-05-11 19:42:16 +00:00
|
|
|
protected:
|
|
|
|
typedef __bitset __self;
|
|
|
|
typedef __storage_type* __storage_pointer;
|
|
|
|
typedef const __storage_type* __const_storage_pointer;
|
|
|
|
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
|
|
|
|
|
|
|
|
friend class __bit_reference<__bitset>;
|
|
|
|
friend class __bit_const_reference<__bitset>;
|
|
|
|
friend class __bit_iterator<__bitset, false>;
|
|
|
|
friend class __bit_iterator<__bitset, true>;
|
2012-08-17 17:10:18 +00:00
|
|
|
friend struct __bit_array<__bitset>;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
__storage_type __first_;
|
|
|
|
|
|
|
|
typedef __bit_reference<__bitset> reference;
|
|
|
|
typedef __bit_const_reference<__bitset> const_reference;
|
|
|
|
typedef __bit_iterator<__bitset, false> iterator;
|
|
|
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return reference(&__first_, __storage_type(1) << __pos);}
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_reference(&__first_, __storage_type(1) << __pos);}
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator&=(const __bitset& __v) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator|=(const __bitset& __v) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void operator^=(const __bitset& __v) _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
void flip() _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long to_ulong() const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long to_ullong() const;
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool all() const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool any() const _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t __hash_code() const _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::__bitset() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
: __first_(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
|
2017-11-27 19:03:30 +00:00
|
|
|
: __first_(
|
|
|
|
_Size == __bits_per_word ? static_cast<__storage_type>(__v)
|
|
|
|
: static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
|
|
|
|
)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__first_ &= __v.__first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__first_ |= __v.__first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__first_ ^= __v.__first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::flip() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
|
|
|
|
__first_ = ~__first_;
|
|
|
|
__first_ &= __m;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long
|
|
|
|
__bitset<1, _Size>::to_ulong() const
|
|
|
|
{
|
|
|
|
return __first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long
|
|
|
|
__bitset<1, _Size>::to_ullong() const
|
|
|
|
{
|
|
|
|
return __first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::all() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
|
|
|
|
return !(~__first_ & __m);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::any() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
|
|
|
|
return __first_ & __m;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
size_t
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<1, _Size>::__hash_code() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return __first_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class __bitset<0, 0>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef size_t size_type;
|
2012-05-07 16:50:38 +00:00
|
|
|
typedef size_type __storage_type;
|
2010-05-11 19:42:16 +00:00
|
|
|
protected:
|
|
|
|
typedef __bitset __self;
|
|
|
|
typedef __storage_type* __storage_pointer;
|
|
|
|
typedef const __storage_type* __const_storage_pointer;
|
|
|
|
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
|
|
|
|
|
|
|
|
friend class __bit_reference<__bitset>;
|
|
|
|
friend class __bit_const_reference<__bitset>;
|
|
|
|
friend class __bit_iterator<__bitset, false>;
|
|
|
|
friend class __bit_iterator<__bitset, true>;
|
2011-12-01 20:21:04 +00:00
|
|
|
friend struct __bit_array<__bitset>;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
typedef __bit_reference<__bitset> reference;
|
|
|
|
typedef __bit_const_reference<__bitset> const_reference;
|
|
|
|
typedef __bit_iterator<__bitset, false> iterator;
|
|
|
|
typedef __bit_iterator<__bitset, true> const_iterator;
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2012-07-07 17:04:52 +00:00
|
|
|
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return reference(0, 1);}
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_reference(0, 1);}
|
2011-12-01 20:21:04 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return iterator(0, 0);}
|
2011-12-01 20:21:04 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return const_iterator(0, 0);}
|
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
|
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2011-05-27 20:52:28 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
|
2010-05-11 19:42:16 +00:00
|
|
|
};
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<0, 0>::__bitset() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_CONSTEXPR
|
2011-05-27 20:52:28 +00:00
|
|
|
__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-04 23:56:00 +00:00
|
|
|
template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
|
2016-04-21 22:54:21 +00:00
|
|
|
template <size_t _Size> struct hash<bitset<_Size> >;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
template <size_t _Size>
|
2017-01-04 23:56:00 +00:00
|
|
|
class _LIBCPP_TEMPLATE_VIS bitset
|
2010-05-11 19:42:16 +00:00
|
|
|
: private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
|
|
|
|
{
|
2013-03-06 17:30:26 +00:00
|
|
|
public:
|
2010-05-11 19:42:16 +00:00
|
|
|
static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
|
|
|
|
typedef __bitset<__n_words, _Size> base;
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
public:
|
2010-05-11 19:42:16 +00:00
|
|
|
typedef typename base::reference reference;
|
|
|
|
typedef typename base::const_reference const_reference;
|
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// 23.3.5.1 constructors:
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
|
|
|
bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
|
2019-07-01 19:59:34 +00:00
|
|
|
template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
|
2010-11-17 21:53:14 +00:00
|
|
|
explicit bitset(const _CharT* __str,
|
|
|
|
typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
|
|
|
|
_CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
|
2010-08-22 00:02:43 +00:00
|
|
|
template<class _CharT, class _Traits, class _Allocator>
|
|
|
|
explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
|
|
|
|
typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
|
|
|
|
typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
|
2010-05-11 19:42:16 +00:00
|
|
|
(basic_string<_CharT,_Traits,_Allocator>::npos),
|
2010-08-22 00:02:43 +00:00
|
|
|
_CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2010-08-22 00:02:43 +00:00
|
|
|
// 23.3.5.2 bitset operations:
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
|
|
|
|
bitset& operator<<=(size_t __pos) _NOEXCEPT;
|
|
|
|
bitset& operator>>=(size_t __pos) _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& set() _NOEXCEPT;
|
2010-08-22 00:02:43 +00:00
|
|
|
bitset& set(size_t __pos, bool __val = true);
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& reset() _NOEXCEPT;
|
2010-08-22 00:02:43 +00:00
|
|
|
bitset& reset(size_t __pos);
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset operator~() const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset& flip() _NOEXCEPT;
|
2010-08-22 00:02:43 +00:00
|
|
|
bitset& flip(size_t __pos);
|
|
|
|
|
|
|
|
// element access:
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
|
|
|
|
const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-22 00:02:43 +00:00
|
|
|
unsigned long to_ulong() const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-22 00:02:43 +00:00
|
|
|
unsigned long long to_ullong() const;
|
|
|
|
template <class _CharT, class _Traits, class _Allocator>
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
|
2010-08-22 00:02:43 +00:00
|
|
|
_CharT __one = _CharT('1')) const;
|
|
|
|
template <class _CharT, class _Traits>
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
|
2010-08-22 00:02:43 +00:00
|
|
|
_CharT __one = _CharT('1')) const;
|
|
|
|
template <class _CharT>
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
|
2010-08-22 00:02:43 +00:00
|
|
|
_CharT __one = _CharT('1')) const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
|
2010-08-22 00:02:43 +00:00
|
|
|
char __one = '1') const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t count() const _NOEXCEPT;
|
2012-07-07 17:04:52 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool operator==(const bitset& __rhs) const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool operator!=(const bitset& __rhs) const _NOEXCEPT;
|
2010-08-22 00:02:43 +00:00
|
|
|
bool test(size_t __pos) const;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool all() const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bool any() const _NOEXCEPT;
|
|
|
|
_LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset operator<<(size_t __pos) const _NOEXCEPT;
|
2015-11-07 01:22:13 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset operator>>(size_t __pos) const _NOEXCEPT;
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-09-21 21:28:23 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
friend struct hash<bitset>;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2019-07-01 19:59:34 +00:00
|
|
|
template<class _CharT, class>
|
2010-11-17 21:53:14 +00:00
|
|
|
bitset<_Size>::bitset(const _CharT* __str,
|
|
|
|
typename basic_string<_CharT>::size_type __n,
|
|
|
|
_CharT __zero, _CharT __one)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
|
2010-05-11 19:42:16 +00:00
|
|
|
for (size_t __i = 0; __i < __rlen; ++__i)
|
2010-11-17 21:53:14 +00:00
|
|
|
if (__str[__i] != __zero && __str[__i] != __one)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_invalid_argument("bitset string ctor has invalid argument");
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
size_t _Mp = _VSTD::min(__rlen, _Size);
|
2010-05-11 19:42:16 +00:00
|
|
|
size_t __i = 0;
|
2011-11-29 18:15:50 +00:00
|
|
|
for (; __i < _Mp; ++__i)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
_CharT __c = __str[_Mp - 1 - __i];
|
2010-11-17 21:53:14 +00:00
|
|
|
if (__c == __zero)
|
2010-05-11 19:42:16 +00:00
|
|
|
(*this)[__i] = false;
|
2010-11-17 21:53:14 +00:00
|
|
|
else
|
2010-05-11 19:42:16 +00:00
|
|
|
(*this)[__i] = true;
|
|
|
|
}
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2010-08-22 00:02:43 +00:00
|
|
|
template<class _CharT, class _Traits, class _Allocator>
|
|
|
|
bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
|
|
|
|
typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
|
2010-05-11 19:42:16 +00:00
|
|
|
typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
|
|
|
|
_CharT __zero, _CharT __one)
|
|
|
|
{
|
|
|
|
if (__pos > __str.size())
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_out_of_range("bitset string pos out of range");
|
|
|
|
|
2011-06-30 21:18:19 +00:00
|
|
|
size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
|
2010-05-11 19:42:16 +00:00
|
|
|
for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
|
|
|
|
if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_invalid_argument("bitset string ctor has invalid argument");
|
|
|
|
|
2011-11-29 18:15:50 +00:00
|
|
|
size_t _Mp = _VSTD::min(__rlen, _Size);
|
2010-05-11 19:42:16 +00:00
|
|
|
size_t __i = 0;
|
2011-11-29 18:15:50 +00:00
|
|
|
for (; __i < _Mp; ++__i)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-11-29 18:15:50 +00:00
|
|
|
_CharT __c = __str[__pos + _Mp - 1 - __i];
|
2010-05-11 19:42:16 +00:00
|
|
|
if (_Traits::eq(__c, __zero))
|
|
|
|
(*this)[__i] = false;
|
|
|
|
else
|
|
|
|
(*this)[__i] = true;
|
|
|
|
}
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
base::operator&=(__rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
base::operator|=(__rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
base::operator^=(__rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
__pos = _VSTD::min(__pos, _Size);
|
|
|
|
_VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
|
|
|
|
_VSTD::fill_n(base::__make_iter(0), __pos, false);
|
2010-05-11 19:42:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
__pos = _VSTD::min(__pos, _Size);
|
|
|
|
_VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
|
|
|
|
_VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
|
2010-05-11 19:42:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::set() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill_n(base::__make_iter(0), _Size, true);
|
2010-05-11 19:42:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bitset<_Size>&
|
|
|
|
bitset<_Size>::set(size_t __pos, bool __val)
|
|
|
|
{
|
|
|
|
if (__pos >= _Size)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_out_of_range("bitset set argument out of range");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
(*this)[__pos] = __val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::reset() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
_VSTD::fill_n(base::__make_iter(0), _Size, false);
|
2010-05-11 19:42:16 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bitset<_Size>&
|
|
|
|
bitset<_Size>::reset(size_t __pos)
|
|
|
|
{
|
|
|
|
if (__pos >= _Size)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_out_of_range("bitset reset argument out of range");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
(*this)[__pos] = false;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator~() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset __x(*this);
|
|
|
|
__x.flip();
|
|
|
|
return __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>&
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::flip() _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
base::flip();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bitset<_Size>&
|
|
|
|
bitset<_Size>::flip(size_t __pos)
|
|
|
|
{
|
|
|
|
if (__pos >= _Size)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_out_of_range("bitset flip argument out of range");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
reference r = base::__make_ref(__pos);
|
|
|
|
r = ~r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long
|
|
|
|
bitset<_Size>::to_ulong() const
|
|
|
|
{
|
|
|
|
return base::to_ulong();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned long long
|
|
|
|
bitset<_Size>::to_ullong() const
|
|
|
|
{
|
|
|
|
return base::to_ullong();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _CharT, class _Traits, class _Allocator>
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, _Traits, _Allocator>
|
|
|
|
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
|
|
|
|
{
|
|
|
|
basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
|
|
|
|
for (size_t __i = 0; __i < _Size; ++__i)
|
|
|
|
{
|
|
|
|
if ((*this)[__i])
|
|
|
|
__r[_Size - 1 - __i] = __one;
|
|
|
|
}
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _CharT, class _Traits>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, _Traits, allocator<_CharT> >
|
|
|
|
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
|
|
|
|
{
|
|
|
|
return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2010-08-22 00:02:43 +00:00
|
|
|
template <class _CharT>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
|
|
|
|
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
|
|
|
|
{
|
|
|
|
return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
basic_string<char, char_traits<char>, allocator<char> >
|
|
|
|
bitset<_Size>::to_string(char __zero, char __one) const
|
|
|
|
{
|
|
|
|
return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
size_t
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::count() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2019-01-11 17:31:17 +00:00
|
|
|
return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size));
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2011-06-30 21:18:19 +00:00
|
|
|
return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return !(*this == __rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
bool
|
|
|
|
bitset<_Size>::test(size_t __pos) const
|
|
|
|
{
|
|
|
|
if (__pos >= _Size)
|
2016-08-25 15:09:01 +00:00
|
|
|
__throw_out_of_range("bitset test argument out of range");
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
return (*this)[__pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::all() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return base::all();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bool
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::any() const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
return base::any();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset __r = *this;
|
|
|
|
__r <<= __pos;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2015-11-07 01:22:13 +00:00
|
|
|
inline
|
2010-05-11 19:42:16 +00:00
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset __r = *this;
|
|
|
|
__r >>= __pos;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset<_Size> __r = __x;
|
|
|
|
__r &= __y;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset<_Size> __r = __x;
|
|
|
|
__r |= __y;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bitset<_Size>
|
2011-05-27 20:52:28 +00:00
|
|
|
operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
bitset<_Size> __r = __x;
|
|
|
|
__r ^= __y;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t _Size>
|
2017-01-04 23:56:00 +00:00
|
|
|
struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
|
2010-05-11 19:42:16 +00:00
|
|
|
: public unary_function<bitset<_Size>, size_t>
|
|
|
|
{
|
2010-09-21 21:28:23 +00:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 20:52:28 +00:00
|
|
|
size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
|
2010-05-11 19:42:16 +00:00
|
|
|
{return __bs.__hash_code();}
|
|
|
|
};
|
|
|
|
|
2011-07-18 15:51:59 +00:00
|
|
|
template <class _CharT, class _Traits, size_t _Size>
|
|
|
|
basic_istream<_CharT, _Traits>&
|
|
|
|
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
|
|
|
|
|
|
|
|
template <class _CharT, class _Traits, size_t _Size>
|
|
|
|
basic_ostream<_CharT, _Traits>&
|
|
|
|
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2017-05-31 22:07:49 +00:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
#endif // _LIBCPP_BITSET
|