xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/profile/bitset (revision c0a68be459da21030695f60d10265c2fc49758f8)
136ac495dSmrg// Profiling bitset implementation -*- C++ -*-
236ac495dSmrg
3*c0a68be4Smrg// Copyright (C) 2009-2019 Free Software Foundation, Inc.
436ac495dSmrg//
536ac495dSmrg// This file is part of the GNU ISO C++ Library.  This library is free
636ac495dSmrg// software; you can redistribute it and/or modify it under the
736ac495dSmrg// terms of the GNU General Public License as published by the
836ac495dSmrg// Free Software Foundation; either version 3, or (at your option)
936ac495dSmrg// any later version.
1036ac495dSmrg
1136ac495dSmrg// This library is distributed in the hope that it will be useful,
1236ac495dSmrg// but WITHOUT ANY WARRANTY; without even the implied warranty of
1336ac495dSmrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1436ac495dSmrg// GNU General Public License for more details.
1536ac495dSmrg
1636ac495dSmrg// Under Section 7 of GPL version 3, you are granted additional
1736ac495dSmrg// permissions described in the GCC Runtime Library Exception, version
1836ac495dSmrg// 3.1, as published by the Free Software Foundation.
1936ac495dSmrg
2036ac495dSmrg// You should have received a copy of the GNU General Public License and
2136ac495dSmrg// a copy of the GCC Runtime Library Exception along with this program;
2236ac495dSmrg// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2336ac495dSmrg// <http://www.gnu.org/licenses/>.
2436ac495dSmrg
2536ac495dSmrg/** @file profile/bitset
2636ac495dSmrg *  This file is a GNU profile extension to the Standard C++ Library.
2736ac495dSmrg */
2836ac495dSmrg
2936ac495dSmrg#ifndef _GLIBCXX_PROFILE_BITSET
3036ac495dSmrg#define _GLIBCXX_PROFILE_BITSET
3136ac495dSmrg
3236ac495dSmrg#include <bitset>
3336ac495dSmrg
3436ac495dSmrgnamespace std _GLIBCXX_VISIBILITY(default)
3536ac495dSmrg{
3636ac495dSmrgnamespace __profile
3736ac495dSmrg{
3836ac495dSmrg  /// Class std::bitset wrapper with performance instrumentation, none at the
3936ac495dSmrg  /// moment.
4036ac495dSmrg  template<size_t _Nb>
4136ac495dSmrg    class bitset
4236ac495dSmrg    : public _GLIBCXX_STD_C::bitset<_Nb>
4336ac495dSmrg    {
4436ac495dSmrg      typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
4536ac495dSmrg
4636ac495dSmrg    public:
4736ac495dSmrg      // 23.3.5.1 constructors:
4836ac495dSmrg#if __cplusplus < 201103L
4936ac495dSmrg      bitset()
5036ac495dSmrg      : _Base() { }
5136ac495dSmrg#else
5236ac495dSmrg      constexpr bitset() = default;
5336ac495dSmrg#endif
5436ac495dSmrg
5536ac495dSmrg#if __cplusplus >= 201103L
5636ac495dSmrg      constexpr bitset(unsigned long long __val) noexcept
5736ac495dSmrg#else
5836ac495dSmrg      bitset(unsigned long __val)
5936ac495dSmrg#endif
6036ac495dSmrg      : _Base(__val) { }
6136ac495dSmrg
6236ac495dSmrg      template<typename _CharT, typename _Traits, typename _Alloc>
6336ac495dSmrg	explicit
6436ac495dSmrg	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
6536ac495dSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
6636ac495dSmrg	       __pos = 0,
6736ac495dSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
6836ac495dSmrg	       __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos))
6936ac495dSmrg	: _Base(__str, __pos, __n) { }
7036ac495dSmrg
7136ac495dSmrg      // _GLIBCXX_RESOLVE_LIB_DEFECTS
7236ac495dSmrg      // 396. what are characters zero and one.
7336ac495dSmrg      template<class _CharT, class _Traits, class _Alloc>
7436ac495dSmrg	bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str,
7536ac495dSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
7636ac495dSmrg	       __pos,
7736ac495dSmrg	       typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
7836ac495dSmrg	       __n,
7936ac495dSmrg	       _CharT __zero, _CharT __one = _CharT('1'))
8036ac495dSmrg	: _Base(__str, __pos, __n, __zero, __one) { }
8136ac495dSmrg
8236ac495dSmrg      bitset(const _Base& __x) : _Base(__x) { }
8336ac495dSmrg
8436ac495dSmrg#if __cplusplus >= 201103L
8536ac495dSmrg      template<typename _CharT>
8636ac495dSmrg	explicit
8736ac495dSmrg	bitset(const _CharT* __str,
8836ac495dSmrg	       typename std::basic_string<_CharT>::size_type __n
8936ac495dSmrg	       = std::basic_string<_CharT>::npos,
9036ac495dSmrg	       _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
9136ac495dSmrg	: _Base(__str, __n, __zero, __one) { }
9236ac495dSmrg#endif
9336ac495dSmrg
9436ac495dSmrg      // 23.3.5.2 bitset operations:
9536ac495dSmrg      bitset<_Nb>&
9636ac495dSmrg      operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
9736ac495dSmrg      {
9836ac495dSmrg	_M_base() &= __rhs;
9936ac495dSmrg	return *this;
10036ac495dSmrg      }
10136ac495dSmrg
10236ac495dSmrg      bitset<_Nb>&
10336ac495dSmrg      operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
10436ac495dSmrg      {
10536ac495dSmrg	_M_base() |= __rhs;
10636ac495dSmrg	return *this;
10736ac495dSmrg      }
10836ac495dSmrg
10936ac495dSmrg      bitset<_Nb>&
11036ac495dSmrg      operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
11136ac495dSmrg      {
11236ac495dSmrg	_M_base() ^= __rhs;
11336ac495dSmrg	return *this;
11436ac495dSmrg      }
11536ac495dSmrg
11636ac495dSmrg      bitset<_Nb>&
11736ac495dSmrg      operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
11836ac495dSmrg      {
11936ac495dSmrg	_M_base() <<= __pos;
12036ac495dSmrg	return *this;
12136ac495dSmrg      }
12236ac495dSmrg
12336ac495dSmrg      bitset<_Nb>&
12436ac495dSmrg      operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
12536ac495dSmrg      {
12636ac495dSmrg	_M_base() >>= __pos;
12736ac495dSmrg	return *this;
12836ac495dSmrg      }
12936ac495dSmrg
13036ac495dSmrg      bitset<_Nb>&
13136ac495dSmrg      set() _GLIBCXX_NOEXCEPT
13236ac495dSmrg      {
13336ac495dSmrg	_Base::set();
13436ac495dSmrg	return *this;
13536ac495dSmrg      }
13636ac495dSmrg
13736ac495dSmrg      // _GLIBCXX_RESOLVE_LIB_DEFECTS
13836ac495dSmrg      // 186. bitset::set() second parameter should be bool
13936ac495dSmrg      bitset<_Nb>&
14036ac495dSmrg      set(size_t __pos, bool __val = true)
14136ac495dSmrg      {
14236ac495dSmrg	_Base::set(__pos, __val);
14336ac495dSmrg	return *this;
14436ac495dSmrg      }
14536ac495dSmrg
14636ac495dSmrg      bitset<_Nb>&
14736ac495dSmrg      reset() _GLIBCXX_NOEXCEPT
14836ac495dSmrg      {
14936ac495dSmrg	_Base::reset();
15036ac495dSmrg	return *this;
15136ac495dSmrg      }
15236ac495dSmrg
15336ac495dSmrg      bitset<_Nb>&
15436ac495dSmrg      reset(size_t __pos)
15536ac495dSmrg      {
15636ac495dSmrg	_Base::reset(__pos);
15736ac495dSmrg	return *this;
15836ac495dSmrg      }
15936ac495dSmrg
16036ac495dSmrg      bitset<_Nb>
16136ac495dSmrg      operator~() const _GLIBCXX_NOEXCEPT
16236ac495dSmrg      { return bitset(~_M_base()); }
16336ac495dSmrg
16436ac495dSmrg      bitset<_Nb>&
16536ac495dSmrg      flip() _GLIBCXX_NOEXCEPT
16636ac495dSmrg      {
16736ac495dSmrg	_Base::flip();
16836ac495dSmrg	return *this;
16936ac495dSmrg      }
17036ac495dSmrg
17136ac495dSmrg      bitset<_Nb>&
17236ac495dSmrg      flip(size_t __pos)
17336ac495dSmrg      {
17436ac495dSmrg	_Base::flip(__pos);
17536ac495dSmrg	return *this;
17636ac495dSmrg      }
17736ac495dSmrg
17836ac495dSmrg      bool
17936ac495dSmrg      operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
18036ac495dSmrg      { return _M_base() == __rhs; }
18136ac495dSmrg
18236ac495dSmrg      bool
18336ac495dSmrg      operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
18436ac495dSmrg      { return _M_base() != __rhs; }
18536ac495dSmrg
18636ac495dSmrg      bitset<_Nb>
18736ac495dSmrg      operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
18836ac495dSmrg      { return bitset<_Nb>(_M_base() << __pos); }
18936ac495dSmrg
19036ac495dSmrg      bitset<_Nb>
19136ac495dSmrg      operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
19236ac495dSmrg      { return bitset<_Nb>(_M_base() >> __pos); }
19336ac495dSmrg
19436ac495dSmrg      _Base&
19536ac495dSmrg      _M_base() _GLIBCXX_NOEXCEPT
19636ac495dSmrg      { return *this; }
19736ac495dSmrg
19836ac495dSmrg      const _Base&
19936ac495dSmrg      _M_base() const _GLIBCXX_NOEXCEPT
20036ac495dSmrg      { return *this; }
20136ac495dSmrg    };
20236ac495dSmrg
20336ac495dSmrg  template<size_t _Nb>
20436ac495dSmrg    bitset<_Nb>
20536ac495dSmrg    operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
20636ac495dSmrg    { return bitset<_Nb>(__x) &= __y; }
20736ac495dSmrg
20836ac495dSmrg  template<size_t _Nb>
20936ac495dSmrg    bitset<_Nb>
21036ac495dSmrg    operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
21136ac495dSmrg    { return bitset<_Nb>(__x) |= __y; }
21236ac495dSmrg
21336ac495dSmrg  template<size_t _Nb>
21436ac495dSmrg    bitset<_Nb>
21536ac495dSmrg    operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
21636ac495dSmrg    { return bitset<_Nb>(__x) ^= __y; }
21736ac495dSmrg
21836ac495dSmrg  template<typename _CharT, typename _Traits, size_t _Nb>
21936ac495dSmrg    std::basic_istream<_CharT, _Traits>&
22036ac495dSmrg    operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
22136ac495dSmrg    { return __is >> __x._M_base(); }
22236ac495dSmrg
22336ac495dSmrg  template<typename _CharT, typename _Traits, size_t _Nb>
22436ac495dSmrg    std::basic_ostream<_CharT, _Traits>&
22536ac495dSmrg    operator<<(std::basic_ostream<_CharT, _Traits>& __os,
22636ac495dSmrg	       const bitset<_Nb>& __x)
22736ac495dSmrg    { return __os << __x._M_base(); }
22836ac495dSmrg} // namespace __profile
22936ac495dSmrg
23036ac495dSmrg#if __cplusplus >= 201103L
23136ac495dSmrg  // DR 1182.
23236ac495dSmrg  /// std::hash specialization for bitset.
23336ac495dSmrg  template<size_t _Nb>
23436ac495dSmrg    struct hash<__profile::bitset<_Nb>>
23536ac495dSmrg    : public __hash_base<size_t, __profile::bitset<_Nb>>
23636ac495dSmrg    {
23736ac495dSmrg      size_t
23836ac495dSmrg      operator()(const __profile::bitset<_Nb>& __b) const noexcept
23936ac495dSmrg      { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); }
24036ac495dSmrg    };
24136ac495dSmrg#endif
24236ac495dSmrg
24336ac495dSmrg} // namespace std
24436ac495dSmrg
24536ac495dSmrg#endif
246