38 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___BIT_HAS_SINGLE_BIT_H10#define _LIBCPP___BIT_HAS_SINGLE_BIT_H11 12#include <__config>13#include <__type_traits/integer_traits.h>14 15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)16# pragma GCC system_header17#endif18 19_LIBCPP_PUSH_MACROS20#include <__undef_macros>21 22#if _LIBCPP_STD_VER >= 2023 24_LIBCPP_BEGIN_NAMESPACE_STD25 26template <__unsigned_integer _Tp>27[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {28 return __builtin_popcountg(__t) == 1;29}30 31_LIBCPP_END_NAMESPACE_STD32 33#endif // _LIBCPP_STD_VER >= 2034 35_LIBCPP_POP_MACROS36 37#endif // _LIBCPP___BIT_HAS_SINGLE_BIT_H38