xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/profile/bitset (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj// Profiling bitset implementation -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj// Copyright (C) 2009-2018 Free Software Foundation, Inc.
4*38fd1498Szrj//
5*38fd1498Szrj// This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj// software; you can redistribute it and/or modify it under the
7*38fd1498Szrj// terms of the GNU General Public License as published by the
8*38fd1498Szrj// Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj// any later version.
10*38fd1498Szrj
11*38fd1498Szrj// This library is distributed in the hope that it will be useful,
12*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj// GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj// 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj// You should have received a copy of the GNU General Public License and
21*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj// <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj/** @file profile/bitset
26*38fd1498Szrj *  This file is a GNU profile extension to the Standard C++ Library.
27*38fd1498Szrj */
28*38fd1498Szrj
29*38fd1498Szrj#ifndef _GLIBCXX_PROFILE_BITSET
30*38fd1498Szrj#define _GLIBCXX_PROFILE_BITSET
31*38fd1498Szrj
32*38fd1498Szrj#include <bitset>
33*38fd1498Szrj
34*38fd1498Szrjnamespace std _GLIBCXX_VISIBILITY(default)
35*38fd1498Szrj{
36*38fd1498Szrjnamespace __profile
37*38fd1498Szrj{
38*38fd1498Szrj  /// Class std::bitset wrapper with performance instrumentation, none at the
39*38fd1498Szrj  /// moment.
40*38fd1498Szrj  template<size_t _Nb>
41*38fd1498Szrj    class bitset
42*38fd1498Szrj    : public _GLIBCXX_STD_C::bitset<_Nb>
43*38fd1498Szrj    {
44*38fd1498Szrj      typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
45*38fd1498Szrj
46*38fd1498Szrj    public:
47*38fd1498Szrj      // 23.3.5.1 constructors:
48*38fd1498Szrj#if __cplusplus < 201103L
49*38fd1498Szrj      bitset()
50*38fd1498Szrj      : _Base() { }
51*38fd1498Szrj#else
52*38fd1498Szrj      constexpr bitset() = default;
53*38fd1498Szrj#endif
54*38fd1498Szrj
55*38fd1498Szrj#if __cplusplus >= 201103L
56*38fd1498Szrj      constexpr bitset(unsigned long long __val) noexcept
57*38fd1498Szrj#else
58*38fd1498Szrj      bitset(unsigned long __val)
59*38fd1498Szrj#endif
60*38fd1498Szrj      : _Base(__val) { }
61*38fd1498Szrj
62*38fd1498Szrj      template<typename _CharT, typename _Traits, typename _Alloc>
63*38fd1498Szrj	explicit
64*38fd1498Szrj	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
65*38fd1498Szrj	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
66*38fd1498Szrj	       __pos = 0,
67*38fd1498Szrj	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
68*38fd1498Szrj	       __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos))
69*38fd1498Szrj	: _Base(__str, __pos, __n) { }
70*38fd1498Szrj
71*38fd1498Szrj      // _GLIBCXX_RESOLVE_LIB_DEFECTS
72*38fd1498Szrj      // 396. what are characters zero and one.
73*38fd1498Szrj      template<class _CharT, class _Traits, class _Alloc>
74*38fd1498Szrj	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
75*38fd1498Szrj	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
76*38fd1498Szrj	       __pos,
77*38fd1498Szrj	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
78*38fd1498Szrj	       __n,
79*38fd1498Szrj	       _CharT __zero, _CharT __one = _CharT('1'))
80*38fd1498Szrj	: _Base(__str, __pos, __n, __zero, __one) { }
81*38fd1498Szrj
82*38fd1498Szrj      bitset(const _Base& __x) : _Base(__x) { }
83*38fd1498Szrj
84*38fd1498Szrj#if __cplusplus >= 201103L
85*38fd1498Szrj      template<typename _CharT>
86*38fd1498Szrj	explicit
87*38fd1498Szrj	bitset(const _CharT* __str,
88*38fd1498Szrj	       typename std::basic_string<_CharT>::size_type __n
89*38fd1498Szrj	       = std::basic_string<_CharT>::npos,
90*38fd1498Szrj	       _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
91*38fd1498Szrj	: _Base(__str, __n, __zero, __one) { }
92*38fd1498Szrj#endif
93*38fd1498Szrj
94*38fd1498Szrj      // 23.3.5.2 bitset operations:
95*38fd1498Szrj      bitset<_Nb>&
96*38fd1498Szrj      operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
97*38fd1498Szrj      {
98*38fd1498Szrj	_M_base() &= __rhs;
99*38fd1498Szrj	return *this;
100*38fd1498Szrj      }
101*38fd1498Szrj
102*38fd1498Szrj      bitset<_Nb>&
103*38fd1498Szrj      operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
104*38fd1498Szrj      {
105*38fd1498Szrj	_M_base() |= __rhs;
106*38fd1498Szrj	return *this;
107*38fd1498Szrj      }
108*38fd1498Szrj
109*38fd1498Szrj      bitset<_Nb>&
110*38fd1498Szrj      operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
111*38fd1498Szrj      {
112*38fd1498Szrj	_M_base() ^= __rhs;
113*38fd1498Szrj	return *this;
114*38fd1498Szrj      }
115*38fd1498Szrj
116*38fd1498Szrj      bitset<_Nb>&
117*38fd1498Szrj      operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
118*38fd1498Szrj      {
119*38fd1498Szrj	_M_base() <<= __pos;
120*38fd1498Szrj	return *this;
121*38fd1498Szrj      }
122*38fd1498Szrj
123*38fd1498Szrj      bitset<_Nb>&
124*38fd1498Szrj      operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
125*38fd1498Szrj      {
126*38fd1498Szrj	_M_base() >>= __pos;
127*38fd1498Szrj	return *this;
128*38fd1498Szrj      }
129*38fd1498Szrj
130*38fd1498Szrj      bitset<_Nb>&
131*38fd1498Szrj      set() _GLIBCXX_NOEXCEPT
132*38fd1498Szrj      {
133*38fd1498Szrj	_Base::set();
134*38fd1498Szrj	return *this;
135*38fd1498Szrj      }
136*38fd1498Szrj
137*38fd1498Szrj      // _GLIBCXX_RESOLVE_LIB_DEFECTS
138*38fd1498Szrj      // 186. bitset::set() second parameter should be bool
139*38fd1498Szrj      bitset<_Nb>&
140*38fd1498Szrj      set(size_t __pos, bool __val = true)
141*38fd1498Szrj      {
142*38fd1498Szrj	_Base::set(__pos, __val);
143*38fd1498Szrj	return *this;
144*38fd1498Szrj      }
145*38fd1498Szrj
146*38fd1498Szrj      bitset<_Nb>&
147*38fd1498Szrj      reset() _GLIBCXX_NOEXCEPT
148*38fd1498Szrj      {
149*38fd1498Szrj	_Base::reset();
150*38fd1498Szrj	return *this;
151*38fd1498Szrj      }
152*38fd1498Szrj
153*38fd1498Szrj      bitset<_Nb>&
154*38fd1498Szrj      reset(size_t __pos)
155*38fd1498Szrj      {
156*38fd1498Szrj	_Base::reset(__pos);
157*38fd1498Szrj	return *this;
158*38fd1498Szrj      }
159*38fd1498Szrj
160*38fd1498Szrj      bitset<_Nb>
161*38fd1498Szrj      operator~() const _GLIBCXX_NOEXCEPT
162*38fd1498Szrj      { return bitset(~_M_base()); }
163*38fd1498Szrj
164*38fd1498Szrj      bitset<_Nb>&
165*38fd1498Szrj      flip() _GLIBCXX_NOEXCEPT
166*38fd1498Szrj      {
167*38fd1498Szrj	_Base::flip();
168*38fd1498Szrj	return *this;
169*38fd1498Szrj      }
170*38fd1498Szrj
171*38fd1498Szrj      bitset<_Nb>&
172*38fd1498Szrj      flip(size_t __pos)
173*38fd1498Szrj      {
174*38fd1498Szrj	_Base::flip(__pos);
175*38fd1498Szrj	return *this;
176*38fd1498Szrj      }
177*38fd1498Szrj
178*38fd1498Szrj      bool
179*38fd1498Szrj      operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
180*38fd1498Szrj      { return _M_base() == __rhs; }
181*38fd1498Szrj
182*38fd1498Szrj      bool
183*38fd1498Szrj      operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
184*38fd1498Szrj      { return _M_base() != __rhs; }
185*38fd1498Szrj
186*38fd1498Szrj      bitset<_Nb>
187*38fd1498Szrj      operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
188*38fd1498Szrj      { return bitset<_Nb>(_M_base() << __pos); }
189*38fd1498Szrj
190*38fd1498Szrj      bitset<_Nb>
191*38fd1498Szrj      operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
192*38fd1498Szrj      { return bitset<_Nb>(_M_base() >> __pos); }
193*38fd1498Szrj
194*38fd1498Szrj      _Base&
195*38fd1498Szrj      _M_base() _GLIBCXX_NOEXCEPT
196*38fd1498Szrj      { return *this; }
197*38fd1498Szrj
198*38fd1498Szrj      const _Base&
199*38fd1498Szrj      _M_base() const _GLIBCXX_NOEXCEPT
200*38fd1498Szrj      { return *this; }
201*38fd1498Szrj    };
202*38fd1498Szrj
203*38fd1498Szrj  template<size_t _Nb>
204*38fd1498Szrj    bitset<_Nb>
205*38fd1498Szrj    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
206*38fd1498Szrj    { return bitset<_Nb>(__x) &= __y; }
207*38fd1498Szrj
208*38fd1498Szrj  template<size_t _Nb>
209*38fd1498Szrj    bitset<_Nb>
210*38fd1498Szrj    operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
211*38fd1498Szrj    { return bitset<_Nb>(__x) |= __y; }
212*38fd1498Szrj
213*38fd1498Szrj  template<size_t _Nb>
214*38fd1498Szrj    bitset<_Nb>
215*38fd1498Szrj    operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
216*38fd1498Szrj    { return bitset<_Nb>(__x) ^= __y; }
217*38fd1498Szrj
218*38fd1498Szrj  template<typename _CharT, typename _Traits, size_t _Nb>
219*38fd1498Szrj    std::basic_istream<_CharT, _Traits>&
220*38fd1498Szrj    operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
221*38fd1498Szrj    { return __is >> __x._M_base(); }
222*38fd1498Szrj
223*38fd1498Szrj  template<typename _CharT, typename _Traits, size_t _Nb>
224*38fd1498Szrj    std::basic_ostream<_CharT, _Traits>&
225*38fd1498Szrj    operator<<(std::basic_ostream<_CharT, _Traits>& __os,
226*38fd1498Szrj	       const bitset<_Nb>& __x)
227*38fd1498Szrj    { return __os << __x._M_base(); }
228*38fd1498Szrj} // namespace __profile
229*38fd1498Szrj
230*38fd1498Szrj#if __cplusplus >= 201103L
231*38fd1498Szrj  // DR 1182.
232*38fd1498Szrj  /// std::hash specialization for bitset.
233*38fd1498Szrj  template<size_t _Nb>
234*38fd1498Szrj    struct hash<__profile::bitset<_Nb>>
235*38fd1498Szrj    : public __hash_base<size_t, __profile::bitset<_Nb>>
236*38fd1498Szrj    {
237*38fd1498Szrj      size_t
238*38fd1498Szrj      operator()(const __profile::bitset<_Nb>& __b) const noexcept
239*38fd1498Szrj      { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); }
240*38fd1498Szrj    };
241*38fd1498Szrj#endif
242*38fd1498Szrj
243*38fd1498Szrj} // namespace std
244*38fd1498Szrj
245*38fd1498Szrj#endif
246