| 1 |
/* Copyright (C) 2015 Povilas Kanapickas <[email protected]> |
| 2 |
|
| 3 |
This file is part of cppreference-doc |
| 4 |
|
| 5 |
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 6 |
Unported License. To view a copy of this license, visit |
| 7 |
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative |
| 8 |
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. |
| 9 |
|
| 10 |
Permission is granted to copy, distribute and/or modify this document |
| 11 |
under the terms of the GNU Free Documentation License, Version 1.3 or |
| 12 |
any later version published by the Free Software Foundation; with no |
| 13 |
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef CPPREFERENCE_BITSET_H |
| 17 |
#define CPPREFERENCE_BITSET_H |
| 18 |
|
| 19 |
namespace std { |
| 20 |
|
| 21 |
template<std::size_t N> |
| 22 |
class bitset { |
| 23 |
public: |
| 24 |
|
| 25 |
class reference { |
| 26 |
reference(); |
| 27 |
public: |
| 28 |
~reference(); |
| 29 |
reference& operator=(bool x); |
| 30 |
reference& operator=(const reference& x); |
| 31 |
operator bool() const; |
| 32 |
bool operator~() const; |
| 33 |
reference& flip(); |
| 34 |
}; |
| 35 |
|
| 36 |
#if CPPREFERENCE_STDVER <2011 |
| 37 |
bitset(); |
| 38 |
bitset(unsigned long val); |
| 39 |
template<class CharT, class Traits, class Alloc> |
| 40 |
explicit bitset(const std::basic_string<CharT, Traits, Alloc>& str, |
| 41 |
typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0, |
| 42 |
typename std::basic_string<CharT, Traits, Alloc>::size_type n = |
| 43 |
std::basic_string<CharT, Traits, Alloc>::npos); |
| 44 |
#else |
| 45 |
constexpr bitset(); |
| 46 |
constexpr bitset(unsigned long long val); |
| 47 |
|
| 48 |
template<class CharT, class Traits, class Alloc> |
| 49 |
explicit bitset(const std::basic_string<CharT, Traits, Alloc>& str, |
| 50 |
typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0, |
| 51 |
typename std::basic_string<CharT, Traits, Alloc>::size_type n = |
| 52 |
std::basic_string<CharT, Traits, Alloc>::npos, |
| 53 |
CharT zero = CharT('0'), |
| 54 |
CharT one = CharT('1')); |
| 55 |
|
| 56 |
template<class CharT> |
| 57 |
explicit bitset(const CharT* str, |
| 58 |
typename std::basic_string<CharT>::size_type n = |
| 59 |
std::basic_string<CharT>::npos, |
| 60 |
CharT zero = CharT('0'), |
| 61 |
CharT one = CharT('1')); |
| 62 |
#endif |
| 63 |
|
| 64 |
bool operator==(const bitset<N>& rhs) const; |
| 65 |
bool operator!=(const bitset<N>& rhs) const; |
| 66 |
|
| 67 |
#if CPPREFERENCE_STDVER <2011 |
| 68 |
bool operator[](std::size_t pos) const; |
| 69 |
#else |
| 70 |
constexpr bool operator[](std::size_t pos) const; |
| 71 |
#endif |
| 72 |
reference operator[](std::size_t pos); |
| 73 |
bool test(size_t pos) const; |
| 74 |
|
| 75 |
#if CPPREFERENCE_STDVER>= 2011 |
| 76 |
bool all() const; |
| 77 |
#endif |
| 78 |
bool any() const; |
| 79 |
bool none() const; |
| 80 |
|
| 81 |
size_t count() const; |
| 82 |
|
| 83 |
std::size_t size() const; |
| 84 |
|
| 85 |
bitset<N>& operator&=(const bitset<N>& other); |
| 86 |
bitset<N>& operator|=(const bitset<N>& other); |
| 87 |
bitset<N>& operator^=(const bitset<N>& other); |
| 88 |
bitset<N>& operator~() const; |
| 89 |
|
| 90 |
bitset<N> operator<<(std::size_t pos) const; |
| 91 |
bitset<N>& operator<<=(std::size_t pos); |
| 92 |
bitset<N> operator>>(std::size_t pos) const; |
| 93 |
bitset<N>& operator>>=(std::size_t pos); |
| 94 |
|
| 95 |
bitset<N>& set(); |
| 96 |
bitset<N>& set(size_t pos, bool value = true); |
| 97 |
|
| 98 |
bitset<N>& reset(); |
| 99 |
bitset<N>& reset(size_t pos); |
| 100 |
|
| 101 |
bitset<N>& flip(); |
| 102 |
bitset<N>& flip(size_t pos); |
| 103 |
|
| 104 |
#if CPPREFERENCE_STDVER <2011 |
| 105 |
template<class CharT, class Traits, class Alloc> |
| 106 |
std::basic_string<CharT, Traits, Allocator> to_string() const; |
| 107 |
#else |
| 108 |
template<class CharT = char, |
| 109 |
class Traits = std::char_traits<CharT>, |
| 110 |
class Allocator = std::allocator<CharT>> |
| 111 |
std::basic_string<CharT, Traits, Allocator> |
| 112 |
to_string(CharT zero = CharT('0'), CharT one = CharT('1')) const; |
| 113 |
#endif |
| 114 |
|
| 115 |
unsigned long to_ulong() const; |
| 116 |
#if CPPREFERENCE_STDVER>= 2011 |
| 117 |
unsigned long long to_ullong() const; |
| 118 |
#endif |
| 119 |
|
| 120 |
}; |
| 121 |
|
| 122 |
template<std::size_t N> |
| 123 |
bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs); |
| 124 |
template<std::size_t N> |
| 125 |
bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs); |
| 126 |
template<std::size_t N> |
| 127 |
bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs); |
| 128 |
|
| 129 |
template <class CharT, class Traits, size_t N> |
| 130 |
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, |
| 131 |
const bitset<N>& x); |
| 132 |
template <class CharT, class Traits, size_t N> |
| 133 |
std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, |
| 134 |
bitset<N>& x); |
| 135 |
|
| 136 |
} // namespace std |
| 137 |
|
| 138 |
#endif // CPPREFERENCE_BITSET_H |