$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r64200 - in sandbox/SOC/2010/bits_and_ints: boost/integer libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-07-20 10:56:23
Author: murilov
Date: 2010-07-20 10:56:22 EDT (Tue, 20 Jul 2010)
New Revision: 64200
URL: http://svn.boost.org/trac/boost/changeset/64200
Log:
Changed count_trailing_zeros to follow count_leading_zeros's schema
Text files modified: 
   sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp          |    46 ++++++++++++++++++++++++++++++++++----- 
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/count_trailing_zeros_test.cpp |     2                                         
   2 files changed, 41 insertions(+), 7 deletions(-)
Modified: sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp	(original)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/count_trailing_zeros.hpp	2010-07-20 10:56:22 EDT (Tue, 20 Jul 2010)
@@ -10,8 +10,10 @@
 #ifndef BOOST_COUNT_TRAILING_ZEROS_INCLUDED
 #define BOOST_COUNT_TRAILING_ZEROS_INCLUDED
 
-#include <boost/integer/pop_count.hpp>
 #include <boost/cstdint.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_unsigned.hpp>
+#include <boost/integer/pop_count.hpp>
 
 /*
  *	count_trailing_zeros counts the number of consecutive 0's 
@@ -28,15 +30,47 @@
 namespace boost {
 
 #ifdef __GNUC__
+	
+template <typename T>
+inline typename enable_if<is_unsigned<T>, int>::type
+count_trailing_zeros(T value)
+{
+	if (value == 0) {
+		return sizeof(T) << 3;
+	}
+	
+	return __builtin_ctz(unsigned(value));
+}
 
-inline int count_trailing_zeros(uintmax_t value)
+inline int count_trailing_zeros(unsigned int value)
 {
-#ifndef BOOST_HAS_NO_INT64_T
-	return __builtin_ctzll(value); 
-#else
+	if (value == 0) { 
+		return sizeof(unsigned int) << 3;
+	}
+	
         return __builtin_ctz(value);
-#endif
 }
+	
+inline int count_trailing_zeros(unsigned long int value)
+{
+	if (value == 0) { 
+		return sizeof(unsigned long int) << 3;
+	}
+	
+	return __builtin_ctzl(value);
+}
+
+#ifndef BOOST_HAS_NO_INT64_T
+inline int count_trailing_zeros(unsigned long long int value)
+{
+	if (value == 0) { 
+		return sizeof(unsigned long long int) << 3;
+	}
+	
+	return __builtin_ctzll(value);
+}
+#endif
+	
 
 #else
 
Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/count_trailing_zeros_test.cpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/count_trailing_zeros_test.cpp	(original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/count_trailing_zeros_test.cpp	2010-07-20 10:56:22 EDT (Tue, 20 Jul 2010)
@@ -13,7 +13,7 @@
 #include <boost/integer/static_count_trailing_zeros.hpp>
 
 #define COUNT_ZEROS_TEST(x, y) \
-BOOST_TEST((::boost::count_trailing_zeros(x) == y)); \
+BOOST_TEST((::boost::count_trailing_zeros(unsigned(x)) == y)); \
 BOOST_TEST(((::boost::mpl::count_trailing_zeros< ::boost::mpl::integral_c< ::boost::uintmax_t, x> >::value) == y))