[libcxx-commits] [libcxx] 640274f - [libc++][NFC] Refactor __enable_ifs in <cstddef> to be defaulted
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 29 04:04:38 PDT 2023
Author: Nikolas Klauser
Date: 2023-10-29T11:49:50+01:00
New Revision: 640274ff1fe17852615564a80d9f8c69b67f1d59
URL: https://github.com/llvm/llvm-project/commit/640274ff1fe17852615564a80d9f8c69b67f1d59
DIFF: https://github.com/llvm/llvm-project/commit/640274ff1fe17852615564a80d9f8c69b67f1d59.diff
LOG: [libc++][NFC] Refactor __enable_ifs in <cstddef> to be defaulted
template arguments
This makes the library more consistent and reduces the size of mangled
names a bit as a bonus.
Added:
Modified:
libcxx/include/cstddef
Removed:
################################################################################
diff --git a/libcxx/include/cstddef b/libcxx/include/cstddef
index a364e6e551756f9..3844d4a373323db 100644
--- a/libcxx/include/cstddef
+++ b/libcxx/include/cstddef
@@ -112,32 +112,30 @@ _LIBCPP_HIDE_FROM_ABI constexpr byte operator~ (byte __b) noexcept
));
}
-template <class _Tp>
-using _EnableByteOverload = __enable_if_t<is_integral<_Tp>::value, byte>;
-
-template <class _Integer>
-_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
- operator<<=(byte& __lhs, _Integer __shift) noexcept
- { return __lhs = __lhs << __shift; }
-
-template <class _Integer>
-_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer>
- operator<< (byte __lhs, _Integer __shift) noexcept
- { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
-
-template <class _Integer>
-_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer> &
- operator>>=(byte& __lhs, _Integer __shift) noexcept
- { return __lhs = __lhs >> __shift; }
-
-template <class _Integer>
-_LIBCPP_HIDE_FROM_ABI constexpr _EnableByteOverload<_Integer>
- operator>> (byte __lhs, _Integer __shift) noexcept
- { return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
-
-template <class _Integer, class = _EnableByteOverload<_Integer> >
-_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer
- to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
+template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept {
+ return __lhs = __lhs << __shift;
+}
+
+template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept {
+ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift));
+}
+
+template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept {
+ return __lhs = __lhs >> __shift;
+}
+
+template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept {
+ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift));
+}
+
+template <class _Integer, __enable_if_t<is_integral<_Integer>::value, int> = 0>
+_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept {
+ return static_cast<_Integer>(__b);
+}
} // namespace std
More information about the libcxx-commits
mailing list