epoc32/include/stdapis/boost/pending/lowest_bit.hpp
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
// -------------------------------------
williamr@2
     2
// lowest_bit.hpp
williamr@2
     3
//
williamr@2
     4
//           Position of the lowest bit 'on'
williamr@2
     5
//
williamr@2
     6
//       (C) Copyright Gennaro Prota 2003 - 2004.
williamr@2
     7
//
williamr@2
     8
// Distributed under the Boost Software License, Version 1.0.
williamr@2
     9
//    (See accompanying file LICENSE_1_0.txt or copy at
williamr@2
    10
//          http://www.boost.org/LICENSE_1_0.txt)
williamr@2
    11
//
williamr@2
    12
// ------------------------------------------------------
williamr@2
    13
williamr@2
    14
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
williamr@2
    15
#define BOOST_LOWEST_BIT_HPP_GP_20030301
williamr@2
    16
williamr@2
    17
#include <cassert>
williamr@2
    18
#include "boost/pending/integer_log2.hpp"
williamr@2
    19
williamr@2
    20
williamr@2
    21
namespace boost {
williamr@2
    22
williamr@2
    23
    template <typename T>
williamr@2
    24
    int lowest_bit(T x) {
williamr@2
    25
williamr@2
    26
        assert(x >= 1); // PRE
williamr@2
    27
williamr@2
    28
        // clear all bits on except the rightmost one,
williamr@2
    29
        // then calculate the logarithm base 2
williamr@2
    30
        //
williamr@2
    31
        return boost::integer_log2<T>( x - ( x & (x-1) ) );
williamr@2
    32
williamr@2
    33
    }
williamr@2
    34
williamr@2
    35
williamr@2
    36
}
williamr@2
    37
williamr@2
    38
williamr@2
    39
#endif // include guard