epoc32/include/stdapis/boost/pending/lowest_bit.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
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