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