163d1a8abSmrg// Profiling bitset implementation -*- C++ -*-
263d1a8abSmrg
3*0fc04c29Smrg// Copyright (C) 2009-2019 Free Software Foundation, Inc.
463d1a8abSmrg//
563d1a8abSmrg// This file is part of the GNU ISO C++ Library.  This library is free
663d1a8abSmrg// software; you can redistribute it and/or modify it under the
763d1a8abSmrg// terms of the GNU General Public License as published by the
863d1a8abSmrg// Free Software Foundation; either version 3, or (at your option)
963d1a8abSmrg// any later version.
1063d1a8abSmrg
1163d1a8abSmrg// This library is distributed in the hope that it will be useful,
1263d1a8abSmrg// but WITHOUT ANY WARRANTY; without even the implied warranty of
1363d1a8abSmrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1463d1a8abSmrg// GNU General Public License for more details.
1563d1a8abSmrg
1663d1a8abSmrg// Under Section 7 of GPL version 3, you are granted additional
1763d1a8abSmrg// permissions described in the GCC Runtime Library Exception, version
1863d1a8abSmrg// 3.1, as published by the Free Software Foundation.
1963d1a8abSmrg
2063d1a8abSmrg// You should have received a copy of the GNU General Public License and
2163d1a8abSmrg// a copy of the GCC Runtime Library Exception along with this program;
2263d1a8abSmrg// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2363d1a8abSmrg// <http://www.gnu.org/licenses/>.
2463d1a8abSmrg
2563d1a8abSmrg/** @file profile/bitset
2663d1a8abSmrg *  This file is a GNU profile extension to the Standard C++ Library.
2763d1a8abSmrg */
2863d1a8abSmrg
2963d1a8abSmrg#ifndef _GLIBCXX_PROFILE_BITSET
3063d1a8abSmrg#define _GLIBCXX_PROFILE_BITSET
3163d1a8abSmrg
3263d1a8abSmrg#include <bitset>
3363d1a8abSmrg
3463d1a8abSmrgnamespace std _GLIBCXX_VISIBILITY(default)
3563d1a8abSmrg{
3663d1a8abSmrgnamespace __profile
3763d1a8abSmrg{
3863d1a8abSmrg  /// Class std::bitset wrapper with performance instrumentation, none at the
3963d1a8abSmrg  /// moment.
4063d1a8abSmrg  template<size_t _Nb>
4163d1a8abSmrg    class bitset
4263d1a8abSmrg    : public _GLIBCXX_STD_C::bitset<_Nb>
4363d1a8abSmrg    {
4463d1a8abSmrg      typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
4563d1a8abSmrg
4663d1a8abSmrg    public:
4763d1a8abSmrg      // 23.3.5.1 constructors:
4863d1a8abSmrg#if __cplusplus < 201103L
4963d1a8abSmrg      bitset()
5063d1a8abSmrg      : _Base() { }
5163d1a8abSmrg#else
5263d1a8abSmrg      constexpr bitset() = default;
5363d1a8abSmrg#endif
5463d1a8abSmrg
5563d1a8abSmrg#if __cplusplus >= 201103L
5663d1a8abSmrg      constexpr bitset(unsigned long long __val) noexcept
5763d1a8abSmrg#else
5863d1a8abSmrg      bitset(unsigned long __val)
5963d1a8abSmrg#endif
6063d1a8abSmrg      : _Base(__val) { }
6163d1a8abSmrg
6263d1a8abSmrg      template<typename _CharT, typename _Traits, typename _Alloc>
6363d1a8abSmrg	explicit
6463d1a8abSmrg	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
6563d1a8abSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
6663d1a8abSmrg	       __pos = 0,
6763d1a8abSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
6863d1a8abSmrg	       __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos))
6963d1a8abSmrg	: _Base(__str, __pos, __n) { }
7063d1a8abSmrg
7163d1a8abSmrg      // _GLIBCXX_RESOLVE_LIB_DEFECTS
7263d1a8abSmrg      // 396. what are characters zero and one.
7363d1a8abSmrg      template<class _CharT, class _Traits, class _Alloc>
7463d1a8abSmrg	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
7563d1a8abSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
7663d1a8abSmrg	       __pos,
7763d1a8abSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
7863d1a8abSmrg	       __n,
7963d1a8abSmrg	       _CharT __zero, _CharT __one = _CharT('1'))
8063d1a8abSmrg	: _Base(__str, __pos, __n, __zero, __one) { }
8163d1a8abSmrg
8263d1a8abSmrg      bitset(const _Base& __x) : _Base(__x) { }
8363d1a8abSmrg
8463d1a8abSmrg#if __cplusplus >= 201103L
8563d1a8abSmrg      template<typename _CharT>
8663d1a8abSmrg	explicit
8763d1a8abSmrg	bitset(const _CharT* __str,
8863d1a8abSmrg	       typename std::basic_string<_CharT>::size_type __n
8963d1a8abSmrg	       = std::basic_string<_CharT>::npos,
9063d1a8abSmrg	       _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
9163d1a8abSmrg	: _Base(__str, __n, __zero, __one) { }
9263d1a8abSmrg#endif
9363d1a8abSmrg
9463d1a8abSmrg      // 23.3.5.2 bitset operations:
9563d1a8abSmrg      bitset<_Nb>&
9663d1a8abSmrg      operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
9763d1a8abSmrg      {
9863d1a8abSmrg	_M_base() &= __rhs;
9963d1a8abSmrg	return *this;
10063d1a8abSmrg      }
10163d1a8abSmrg
10263d1a8abSmrg      bitset<_Nb>&
10363d1a8abSmrg      operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
10463d1a8abSmrg      {
10563d1a8abSmrg	_M_base() |= __rhs;
10663d1a8abSmrg	return *this;
10763d1a8abSmrg      }
10863d1a8abSmrg
10963d1a8abSmrg      bitset<_Nb>&
11063d1a8abSmrg      operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
11163d1a8abSmrg      {
11263d1a8abSmrg	_M_base() ^= __rhs;
11363d1a8abSmrg	return *this;
11463d1a8abSmrg      }
11563d1a8abSmrg
11663d1a8abSmrg      bitset<_Nb>&
11763d1a8abSmrg      operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
11863d1a8abSmrg      {
11963d1a8abSmrg	_M_base() <<= __pos;
12063d1a8abSmrg	return *this;
12163d1a8abSmrg      }
12263d1a8abSmrg
12363d1a8abSmrg      bitset<_Nb>&
12463d1a8abSmrg      operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
12563d1a8abSmrg      {
12663d1a8abSmrg	_M_base() >>= __pos;
12763d1a8abSmrg	return *this;
12863d1a8abSmrg      }
12963d1a8abSmrg
13063d1a8abSmrg      bitset<_Nb>&
13163d1a8abSmrg      set() _GLIBCXX_NOEXCEPT
13263d1a8abSmrg      {
13363d1a8abSmrg	_Base::set();
13463d1a8abSmrg	return *this;
13563d1a8abSmrg      }
13663d1a8abSmrg
13763d1a8abSmrg      // _GLIBCXX_RESOLVE_LIB_DEFECTS
13863d1a8abSmrg      // 186. bitset::set() second parameter should be bool
13963d1a8abSmrg      bitset<_Nb>&
14063d1a8abSmrg      set(size_t __pos, bool __val = true)
14163d1a8abSmrg      {
14263d1a8abSmrg	_Base::set(__pos, __val);
14363d1a8abSmrg	return *this;
14463d1a8abSmrg      }
14563d1a8abSmrg
14663d1a8abSmrg      bitset<_Nb>&
14763d1a8abSmrg      reset() _GLIBCXX_NOEXCEPT
14863d1a8abSmrg      {
14963d1a8abSmrg	_Base::reset();
15063d1a8abSmrg	return *this;
15163d1a8abSmrg      }
15263d1a8abSmrg
15363d1a8abSmrg      bitset<_Nb>&
15463d1a8abSmrg      reset(size_t __pos)
15563d1a8abSmrg      {
15663d1a8abSmrg	_Base::reset(__pos);
15763d1a8abSmrg	return *this;
15863d1a8abSmrg      }
15963d1a8abSmrg
16063d1a8abSmrg      bitset<_Nb>
16163d1a8abSmrg      operator~() const _GLIBCXX_NOEXCEPT
16263d1a8abSmrg      { return bitset(~_M_base()); }
16363d1a8abSmrg
16463d1a8abSmrg      bitset<_Nb>&
16563d1a8abSmrg      flip() _GLIBCXX_NOEXCEPT
16663d1a8abSmrg      {
16763d1a8abSmrg	_Base::flip();
16863d1a8abSmrg	return *this;
16963d1a8abSmrg      }
17063d1a8abSmrg
17163d1a8abSmrg      bitset<_Nb>&
17263d1a8abSmrg      flip(size_t __pos)
17363d1a8abSmrg      {
17463d1a8abSmrg	_Base::flip(__pos);
17563d1a8abSmrg	return *this;
17663d1a8abSmrg      }
17763d1a8abSmrg
17863d1a8abSmrg      bool
17963d1a8abSmrg      operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
18063d1a8abSmrg      { return _M_base() == __rhs; }
18163d1a8abSmrg
18263d1a8abSmrg      bool
18363d1a8abSmrg      operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
18463d1a8abSmrg      { return _M_base() != __rhs; }
18563d1a8abSmrg
18663d1a8abSmrg      bitset<_Nb>
18763d1a8abSmrg      operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
18863d1a8abSmrg      { return bitset<_Nb>(_M_base() << __pos); }
18963d1a8abSmrg
19063d1a8abSmrg      bitset<_Nb>
19163d1a8abSmrg      operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
19263d1a8abSmrg      { return bitset<_Nb>(_M_base() >> __pos); }
19363d1a8abSmrg
19463d1a8abSmrg      _Base&
19563d1a8abSmrg      _M_base() _GLIBCXX_NOEXCEPT
19663d1a8abSmrg      { return *this; }
19763d1a8abSmrg
19863d1a8abSmrg      const _Base&
19963d1a8abSmrg      _M_base() const _GLIBCXX_NOEXCEPT
20063d1a8abSmrg      { return *this; }
20163d1a8abSmrg    };
20263d1a8abSmrg
20363d1a8abSmrg  template<size_t _Nb>
20463d1a8abSmrg    bitset<_Nb>
20563d1a8abSmrg    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
20663d1a8abSmrg    { return bitset<_Nb>(__x) &= __y; }
20763d1a8abSmrg
20863d1a8abSmrg  template<size_t _Nb>
20963d1a8abSmrg    bitset<_Nb>
21063d1a8abSmrg    operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
21163d1a8abSmrg    { return bitset<_Nb>(__x) |= __y; }
21263d1a8abSmrg
21363d1a8abSmrg  template<size_t _Nb>
21463d1a8abSmrg    bitset<_Nb>
21563d1a8abSmrg    operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
21663d1a8abSmrg    { return bitset<_Nb>(__x) ^= __y; }
21763d1a8abSmrg
21863d1a8abSmrg  template<typename _CharT, typename _Traits, size_t _Nb>
21963d1a8abSmrg    std::basic_istream<_CharT, _Traits>&
22063d1a8abSmrg    operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
22163d1a8abSmrg    { return __is >> __x._M_base(); }
22263d1a8abSmrg
22363d1a8abSmrg  template<typename _CharT, typename _Traits, size_t _Nb>
22463d1a8abSmrg    std::basic_ostream<_CharT, _Traits>&
22563d1a8abSmrg    operator<<(std::basic_ostream<_CharT, _Traits>& __os,
22663d1a8abSmrg	       const bitset<_Nb>& __x)
22763d1a8abSmrg    { return __os << __x._M_base(); }
22863d1a8abSmrg} // namespace __profile
22963d1a8abSmrg
23063d1a8abSmrg#if __cplusplus >= 201103L
23163d1a8abSmrg  // DR 1182.
23263d1a8abSmrg  /// std::hash specialization for bitset.
23363d1a8abSmrg  template<size_t _Nb>
23463d1a8abSmrg    struct hash<__profile::bitset<_Nb>>
23563d1a8abSmrg    : public __hash_base<size_t, __profile::bitset<_Nb>>
23663d1a8abSmrg    {
23763d1a8abSmrg      size_t
23863d1a8abSmrg      operator()(const __profile::bitset<_Nb>& __b) const noexcept
23963d1a8abSmrg      { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); }
24063d1a8abSmrg    };
24163d1a8abSmrg#endif
24263d1a8abSmrg
24363d1a8abSmrg} // namespace std
24463d1a8abSmrg
24563d1a8abSmrg#endif
246