[cfe-commits] [libcxx] r156546 - /libcxx/trunk/include/__bit_reference

Howard Hinnant hhinnant at apple.com
Thu May 10 07:55:00 PDT 2012


Author: hhinnant
Date: Thu May 10 09:55:00 2012
New Revision: 156546

URL: http://llvm.org/viewvc/llvm-project?rev=156546&view=rev
Log:
Fix several bugs in find/count specialized for bits.

Modified:
    libcxx/trunk/include/__bit_reference

Modified: libcxx/trunk/include/__bit_reference
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bit_reference?rev=156546&r1=156545&r2=156546&view=diff
==============================================================================
--- libcxx/trunk/include/__bit_reference (original)
+++ libcxx/trunk/include/__bit_reference Thu May 10 09:55:00 2012
@@ -146,11 +146,11 @@
 
 // find
 
-template <class _Cp>
-__bit_iterator<_Cp, false>
-__find_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
     // do first partial word
@@ -180,11 +180,11 @@
     return _It(__first.__seg_, static_cast<unsigned>(__n));
 }
 
-template <class _Cp>
-__bit_iterator<_Cp, false>
-__find_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+__bit_iterator<_Cp, _IsConst>
+__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
     // do first partial word
@@ -193,7 +193,7 @@
         __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
         __storage_type __dn = _VSTD::min(__clz_f, __n);
         __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
-        __storage_type __b = ~(*__first.__seg_ & __m);
+        __storage_type __b = ~*__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
         __n -= __dn;
@@ -210,17 +210,17 @@
     if (__n > 0)
     {
         __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
-        __storage_type __b = ~(*__first.__seg_ & __m);
+        __storage_type __b = ~*__first.__seg_ & __m;
         if (__b)
             return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
     }
     return _It(__first.__seg_, static_cast<unsigned>(__n));
 }
 
-template <class _Cp, class _Tp>
+template <class _Cp, bool _IsConst, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-__bit_iterator<_Cp, false>
-find(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
+__bit_iterator<_Cp, _IsConst>
+find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
 {
     if (static_cast<bool>(__value_))
         return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
@@ -229,11 +229,11 @@
 
 // count
 
-template <class _Cp>
-typename __bit_iterator<_Cp, false>::difference_type
-__count_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     typedef typename _It::difference_type difference_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -260,11 +260,11 @@
     return __r;
 }
 
-template <class _Cp>
-typename __bit_iterator<_Cp, false>::difference_type
-__count_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
+template <class _Cp, bool _IsConst>
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
 {
-    typedef __bit_iterator<_Cp, false> _It;
+    typedef __bit_iterator<_Cp, _IsConst> _It;
     typedef typename _It::__storage_type __storage_type;
     typedef typename _It::difference_type difference_type;
     static const unsigned __bits_per_word = _It::__bits_per_word;
@@ -275,7 +275,7 @@
         __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
         __storage_type __dn = _VSTD::min(__clz_f, __n);
         __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
-        __r = _VSTD::__pop_count(~(*__first.__seg_ & __m));
+        __r = _VSTD::__pop_count(~*__first.__seg_ & __m);
         __n -= __dn;
         ++__first.__seg_;
     }
@@ -286,15 +286,15 @@
     if (__n > 0)
     {
         __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
-        __r += _VSTD::__pop_count(~(*__first.__seg_ & __m));
+        __r += _VSTD::__pop_count(~*__first.__seg_ & __m);
     }
     return __r;
 }
 
-template <class _Cp, class _Tp>
+template <class _Cp, bool _IsConst, class _Tp>
 inline _LIBCPP_INLINE_VISIBILITY
-typename __bit_iterator<_Cp, false>::difference_type
-count(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
+typename __bit_iterator<_Cp, _IsConst>::difference_type
+count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
 {
     if (static_cast<bool>(__value_))
         return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
@@ -1238,14 +1238,14 @@
     template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
                                                                 __bit_iterator<_Dp, _IC1>,
                                                                 __bit_iterator<_Dp, _IC2>);
-    template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_true(__bit_iterator<_Dp, false>,
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
                                                                           typename _Dp::size_type);
-    template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_false(__bit_iterator<_Dp, false>,
+    template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
                                                                            typename _Dp::size_type);
-    template <class _Dp> friend typename __bit_iterator<_Dp, false>::difference_type
-                   __count_bool_true(__bit_iterator<_Dp, false>, typename _Dp::size_type);
-    template <class _Dp> friend typename __bit_iterator<_Dp, false>::difference_type
-                   __count_bool_false(__bit_iterator<_Dp, false>, typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
+    template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
+                   __count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
 };
 
 _LIBCPP_END_NAMESPACE_STD





More information about the cfe-commits mailing list