[libcxx-commits] [libcxx] [libc++] Implement C++29 Bit Permutations P3104R6 (PR #217820)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Sep 27 10:19:53 PDT 2026


================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++29
+
+#include <bit>
+#include <cstdint>
+
+template <typename T>
+concept can_reverse = requires(T x) { std::bit_reverse(x); };
+
+static_assert(!can_reverse<bool>, "type is not allowed to be reversed");
+static_assert(!can_reverse<float>);
+
+static_assert(!can_reverse<signed char>, "signed integers are not allowed to be reversed");
+static_assert(!can_reverse<short>);
+static_assert(!can_reverse<int>);
+static_assert(!can_reverse<long long>);
+static_assert(!can_reverse<std::int8_t>);
+static_assert(!can_reverse<std::int16_t>);
+static_assert(!can_reverse<std::int32_t>);
+static_assert(!can_reverse<std::int64_t>);
+
+static_assert(!can_reverse<char*>, "pointers are not allowed to be reversed");
+static_assert(!can_reverse<short*>);
+static_assert(!can_reverse<int*>);
+static_assert(!can_reverse<long long*>);
+static_assert(!can_reverse<std::int8_t*>);
+static_assert(!can_reverse<std::int16_t*>);
+static_assert(!can_reverse<std::int32_t*>);
+static_assert(!can_reverse<std::int64_t*>);
+
+int main(int, char**) {
----------------
Zingam wrote:

If all tests are static_asserts you don't need main here and because this is not a runtime test.
But then shouldn't this test be runtime one too? There is a common test pattern that needs to be used.

```c++
constexpr bool test() {
  return true;
}

int main() {
   test();
   static_assert(test());

}
```

https://github.com/llvm/llvm-project/pull/217820


More information about the libcxx-commits mailing list