|
||||
File indexing completed on 2025-01-18 09:30:45
0001 // ----------------------------------------------------------- 0002 // lowest_bit.hpp 0003 // 0004 // Position of the lowest bit 'on' 0005 // 0006 // Copyright (c) 2003-2004, 2008 Gennaro Prota 0007 // 0008 // Distributed under the Boost Software License, Version 1.0. 0009 // (See accompanying file LICENSE_1_0.txt or copy at 0010 // http://www.boost.org/LICENSE_1_0.txt) 0011 // 0012 // ----------------------------------------------------------- 0013 0014 #ifndef BOOST_LOWEST_BIT_HPP_GP_20030301 0015 #define BOOST_LOWEST_BIT_HPP_GP_20030301 0016 0017 #include "boost/integer/integer_log2.hpp" 0018 #include "boost/assert.hpp" 0019 0020 namespace boost { 0021 namespace detail { 0022 0023 template <typename T> 0024 int lowest_bit(T x) { 0025 0026 BOOST_ASSERT(x >= 1); // PRE 0027 0028 // clear all bits on except the rightmost one, 0029 // then calculate the logarithm base 2 0030 // 0031 return boost::integer_log2<T>( x - ( x & (x-1) ) ); 0032 0033 } 0034 0035 } 0036 } 0037 0038 0039 #endif // include guard
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |