summaryrefslogtreecommitdiff
path: root/chromium/base/bits.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/bits.h')
-rw-r--r--chromium/base/bits.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/chromium/base/bits.h b/chromium/base/bits.h
index d2c5ac9caa7..20f2ff278f3 100644
--- a/chromium/base/bits.h
+++ b/chromium/base/bits.h
@@ -7,13 +7,14 @@
#ifndef BASE_BITS_H_
#define BASE_BITS_H_
+#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <type_traits>
+#include "base/check.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "build/build_config.h"
#if defined(COMPILER_MSVC)
@@ -203,6 +204,16 @@ inline int Log2Ceiling(uint32_t n) {
return (n ? 32 : -1) - CountLeadingZeroBits(n - 1);
}
+// Returns a value of type T with a single bit set in the left-most position.
+// Can be used instead of manually shifting a 1 to the left.
+template <typename T>
+constexpr T LeftmostBit() {
+ static_assert(std::is_integral<T>::value,
+ "This function can only be used with integral types.");
+ T one(1u);
+ return one << ((CHAR_BIT * sizeof(T) - 1));
+}
+
} // namespace bits
} // namespace base