1 // Profiling bitset implementation -*- C++ -*-
3 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file profile/bitset
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_BITSET
30 #define _GLIBCXX_PROFILE_BITSET
34 namespace std _GLIBCXX_VISIBILITY(default)
38 /// Class std::bitset wrapper with performance instrumentation, none at the
42 : public _GLIBCXX_STD_C::bitset<_Nb>
44 typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
47 // 23.3.5.1 constructors:
48 #if __cplusplus < 201103L
52 constexpr bitset() = default;
55 #if __cplusplus >= 201103L
56 constexpr bitset(unsigned long long __val) noexcept
58 bitset(unsigned long __val)
62 template<typename _CharT, typename _Traits, typename _Alloc>
64 bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
65 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
67 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
68 __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos))
69 : _Base(__str, __pos, __n) { }
71 // _GLIBCXX_RESOLVE_LIB_DEFECTS
72 // 396. what are characters zero and one.
73 template<class _CharT, class _Traits, class _Alloc>
74 bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
75 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
77 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
79 _CharT __zero, _CharT __one = _CharT('1'))
80 : _Base(__str, __pos, __n, __zero, __one) { }
82 bitset(const _Base& __x) : _Base(__x) { }
84 #if __cplusplus >= 201103L
85 template<typename _CharT>
87 bitset(const _CharT* __str,
88 typename std::basic_string<_CharT>::size_type __n
89 = std::basic_string<_CharT>::npos,
90 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
91 : _Base(__str, __n, __zero, __one) { }
94 // 23.3.5.2 bitset operations:
96 operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
103 operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
110 operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
117 operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
124 operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
131 set() _GLIBCXX_NOEXCEPT
137 // _GLIBCXX_RESOLVE_LIB_DEFECTS
138 // 186. bitset::set() second parameter should be bool
140 set(size_t __pos, bool __val = true)
142 _Base::set(__pos, __val);
147 reset() _GLIBCXX_NOEXCEPT
161 operator~() const _GLIBCXX_NOEXCEPT
162 { return bitset(~_M_base()); }
165 flip() _GLIBCXX_NOEXCEPT
179 operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
180 { return _M_base() == __rhs; }
183 operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
184 { return _M_base() != __rhs; }
187 operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
188 { return bitset<_Nb>(_M_base() << __pos); }
191 operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
192 { return bitset<_Nb>(_M_base() >> __pos); }
195 _M_base() _GLIBCXX_NOEXCEPT
199 _M_base() const _GLIBCXX_NOEXCEPT
205 operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
206 { return bitset<_Nb>(__x) &= __y; }
210 operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
211 { return bitset<_Nb>(__x) |= __y; }
215 operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
216 { return bitset<_Nb>(__x) ^= __y; }
218 template<typename _CharT, typename _Traits, size_t _Nb>
219 std::basic_istream<_CharT, _Traits>&
220 operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
221 { return __is >> __x._M_base(); }
223 template<typename _CharT, typename _Traits, size_t _Nb>
224 std::basic_ostream<_CharT, _Traits>&
225 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
226 const bitset<_Nb>& __x)
227 { return __os << __x._M_base(); }
228 } // namespace __profile
230 #if __cplusplus >= 201103L
232 /// std::hash specialization for bitset.
234 struct hash<__profile::bitset<_Nb>>
235 : public __hash_base<size_t, __profile::bitset<_Nb>>
238 operator()(const __profile::bitset<_Nb>& __b) const noexcept
239 { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); }