Import GCC-8 to a new vendor branch
[dragonfly.git] / contrib / gcc-8.0 / libstdc++-v3 / include / profile / bitset
bloba13898e253352b2c2551ef15af0b0c11499a7aa5
1 // Profiling bitset implementation -*- C++ -*-
3 // Copyright (C) 2009-2018 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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.
27  */
29 #ifndef _GLIBCXX_PROFILE_BITSET
30 #define _GLIBCXX_PROFILE_BITSET
32 #include <bitset>
34 namespace std _GLIBCXX_VISIBILITY(default)
36 namespace __profile
38   /// Class std::bitset wrapper with performance instrumentation, none at the
39   /// moment.
40   template<size_t _Nb>
41     class bitset
42     : public _GLIBCXX_STD_C::bitset<_Nb>
43     {
44       typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
46     public:
47       // 23.3.5.1 constructors:
48 #if __cplusplus < 201103L
49       bitset()
50       : _Base() { }
51 #else
52       constexpr bitset() = default;
53 #endif
55 #if __cplusplus >= 201103L
56       constexpr bitset(unsigned long long __val) noexcept
57 #else
58       bitset(unsigned long __val)
59 #endif
60       : _Base(__val) { }
62       template<typename _CharT, typename _Traits, typename _Alloc>
63         explicit
64         bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
65                typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
66                __pos = 0,
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
76                __pos,
77                typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
78                __n,
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>
86         explicit
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) { }
92 #endif
94       // 23.3.5.2 bitset operations:
95       bitset<_Nb>&
96       operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
97       {
98         _M_base() &= __rhs;
99         return *this;
100       }
102       bitset<_Nb>&
103       operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
104       {
105         _M_base() |= __rhs;
106         return *this;
107       }
109       bitset<_Nb>&
110       operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
111       {
112         _M_base() ^= __rhs;
113         return *this;
114       }
116       bitset<_Nb>&
117       operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
118       {
119         _M_base() <<= __pos;
120         return *this;
121       }
123       bitset<_Nb>&
124       operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
125       {
126         _M_base() >>= __pos;
127         return *this;
128       }
130       bitset<_Nb>&
131       set() _GLIBCXX_NOEXCEPT
132       {
133         _Base::set();
134         return *this;
135       }
137       // _GLIBCXX_RESOLVE_LIB_DEFECTS
138       // 186. bitset::set() second parameter should be bool
139       bitset<_Nb>&
140       set(size_t __pos, bool __val = true)
141       {
142         _Base::set(__pos, __val);
143         return *this;
144       }
146       bitset<_Nb>&
147       reset() _GLIBCXX_NOEXCEPT
148       {
149         _Base::reset();
150         return *this;
151       }
153       bitset<_Nb>&
154       reset(size_t __pos)
155       {
156         _Base::reset(__pos);
157         return *this;
158       }
160       bitset<_Nb>
161       operator~() const _GLIBCXX_NOEXCEPT
162       { return bitset(~_M_base()); }
164       bitset<_Nb>&
165       flip() _GLIBCXX_NOEXCEPT
166       {
167         _Base::flip();
168         return *this;
169       }
171       bitset<_Nb>&
172       flip(size_t __pos)
173       {
174         _Base::flip(__pos);
175         return *this;
176       }
178       bool
179       operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
180       { return _M_base() == __rhs; }
182       bool
183       operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
184       { return _M_base() != __rhs; }
186       bitset<_Nb>
187       operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
188       { return bitset<_Nb>(_M_base() << __pos); }
190       bitset<_Nb>
191       operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
192       { return bitset<_Nb>(_M_base() >> __pos); }
194       _Base&
195       _M_base() _GLIBCXX_NOEXCEPT
196       { return *this; }
198       const _Base&
199       _M_base() const _GLIBCXX_NOEXCEPT
200       { return *this; }
201     };
203   template<size_t _Nb>
204     bitset<_Nb>
205     operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
206     { return bitset<_Nb>(__x) &= __y; }
208   template<size_t _Nb>
209     bitset<_Nb>
210     operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
211     { return bitset<_Nb>(__x) |= __y; }
213   template<size_t _Nb>
214     bitset<_Nb>
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
231   // DR 1182.
232   /// std::hash specialization for bitset.
233   template<size_t _Nb>
234     struct hash<__profile::bitset<_Nb>>
235     : public __hash_base<size_t, __profile::bitset<_Nb>>
236     {
237       size_t
238       operator()(const __profile::bitset<_Nb>& __b) const noexcept
239       { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); }
240     };
241 #endif
243 } // namespace std
245 #endif