bit 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===---------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_BIT
  10. #define _LIBCPP_BIT
  11. /*
  12. bit synopsis
  13. namespace std {
  14. // [bit.cast], bit_cast
  15. template<class To, class From>
  16. constexpr To bit_cast(const From& from) noexcept; // C++20
  17. // [bit.byteswap], byteswap
  18. template<class T>
  19. constexpr T byteswap(T value) noexcept; // C++23
  20. // [bit.pow.two], integral powers of 2
  21. template <class T>
  22. constexpr bool has_single_bit(T x) noexcept; // C++20
  23. template <class T>
  24. constexpr T bit_ceil(T x); // C++20
  25. template <class T>
  26. constexpr T bit_floor(T x) noexcept; // C++20
  27. template <class T>
  28. constexpr int bit_width(T x) noexcept; // C++20
  29. // [bit.rotate], rotating
  30. template<class T>
  31. constexpr T rotl(T x, unsigned int s) noexcept; // C++20
  32. template<class T>
  33. constexpr T rotr(T x, unsigned int s) noexcept; // C++20
  34. // [bit.count], counting
  35. template<class T>
  36. constexpr int countl_zero(T x) noexcept; // C++20
  37. template<class T>
  38. constexpr int countl_one(T x) noexcept; // C++20
  39. template<class T>
  40. constexpr int countr_zero(T x) noexcept; // C++20
  41. template<class T>
  42. constexpr int countr_one(T x) noexcept; // C++20
  43. template<class T>
  44. constexpr int popcount(T x) noexcept; // C++20
  45. // [bit.endian], endian
  46. enum class endian {
  47. little = see below, // C++20
  48. big = see below, // C++20
  49. native = see below // C++20
  50. };
  51. } // namespace std
  52. */
  53. #include <__assert> // all public C++ headers provide the assertion handler
  54. #include <__bit/bit_cast.h>
  55. #include <__bit/bit_ceil.h>
  56. #include <__bit/bit_floor.h>
  57. #include <__bit/bit_log2.h>
  58. #include <__bit/bit_width.h>
  59. #include <__bit/blsr.h>
  60. #include <__bit/byteswap.h>
  61. #include <__bit/countl.h>
  62. #include <__bit/countr.h>
  63. #include <__bit/endian.h>
  64. #include <__bit/has_single_bit.h>
  65. #include <__bit/popcount.h>
  66. #include <__bit/rotate.h>
  67. #include <__config>
  68. #include <version>
  69. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  70. # pragma GCC system_header
  71. #endif
  72. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  73. # include <iosfwd>
  74. # include <limits>
  75. # include <type_traits>
  76. #endif
  77. #endif // _LIBCPP_BIT