[libcxx-commits] [libcxx] bddd8f4 - [libc++][concepts] Implements concept helper `__libcpp_integer` (#78086)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jan 14 14:01:01 PST 2024
Author: Hristo Hristov
Date: 2024-01-15T00:00:57+02:00
New Revision: bddd8f46f81477a52ff7ef2873e5671db71c431e
URL: https://github.com/llvm/llvm-project/commit/bddd8f46f81477a52ff7ef2873e5671db71c431e
DIFF: https://github.com/llvm/llvm-project/commit/bddd8f46f81477a52ff7ef2873e5671db71c431e.diff
LOG: [libc++][concepts] Implements concept helper `__libcpp_integer` (#78086)
...and tests.
---------
Co-authored-by: Zingam <zingam at outlook.com>
Added:
libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_integer.compile.pass.cpp
libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_signed_integer.compile.pass.cpp
libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_unsigned_integer.compile.pass.cpp
Modified:
libcxx/include/__concepts/arithmetic.h
Removed:
################################################################################
diff --git a/libcxx/include/__concepts/arithmetic.h b/libcxx/include/__concepts/arithmetic.h
index f41e4c9f2747cc..0c44f117805f36 100644
--- a/libcxx/include/__concepts/arithmetic.h
+++ b/libcxx/include/__concepts/arithmetic.h
@@ -42,9 +42,13 @@ concept floating_point = is_floating_point_v<_Tp>;
template <class _Tp>
concept __libcpp_unsigned_integer = __libcpp_is_unsigned_integer<_Tp>::value;
+
template <class _Tp>
concept __libcpp_signed_integer = __libcpp_is_signed_integer<_Tp>::value;
+template <class _Tp>
+concept __libcpp_integer = __libcpp_unsigned_integer<_Tp> || __libcpp_signed_integer<_Tp>;
+
#endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_integer.compile.pass.cpp b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_integer.compile.pass.cpp
new file mode 100644
index 00000000000000..55b5929847748f
--- /dev/null
+++ b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_integer.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// Concept helpers for the internal type traits for the fundamental types.
+
+// template <class _Tp>
+// concept __libcpp_integer;
+
+#include <concepts>
+
+#include "test_macros.h"
+
+struct SomeObject {};
+
+enum SomeEnum {};
+
+enum class SomeScopedEnum {};
+
+// Unsigned
+static_assert(std::__libcpp_integer<unsigned char>);
+static_assert(std::__libcpp_integer<unsigned short int>);
+static_assert(std::__libcpp_integer<unsigned int>);
+static_assert(std::__libcpp_integer<unsigned long int>);
+static_assert(std::__libcpp_integer<unsigned long long int>);
+static_assert(std::__libcpp_integer<unsigned short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_integer<__uint128_t>);
+#endif
+// Signed
+static_assert(std::__libcpp_integer<signed char>);
+static_assert(std::__libcpp_integer<short int>);
+static_assert(std::__libcpp_integer<int>);
+static_assert(std::__libcpp_integer<long int>);
+static_assert(std::__libcpp_integer<long long int>);
+static_assert(std::__libcpp_integer<short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_integer<__int128_t>);
+#endif
+// Non-integer
+static_assert(!std::__libcpp_integer<bool>);
+static_assert(!std::__libcpp_integer<char>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::__libcpp_integer<wchar_t>);
+#endif
+static_assert(!std::__libcpp_integer<char8_t>);
+static_assert(!std::__libcpp_integer<char16_t>);
+static_assert(!std::__libcpp_integer<char32_t>);
+static_assert(!std::__libcpp_integer<float>);
+static_assert(!std::__libcpp_integer<double>);
+static_assert(!std::__libcpp_integer<long double>);
+static_assert(!std::__libcpp_integer<void>);
+static_assert(!std::__libcpp_integer<int*>);
+static_assert(!std::__libcpp_integer<unsigned int*>);
+static_assert(!std::__libcpp_integer<SomeObject>);
+static_assert(!std::__libcpp_integer<SomeEnum>);
+static_assert(!std::__libcpp_integer<SomeScopedEnum>);
diff --git a/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_signed_integer.compile.pass.cpp b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_signed_integer.compile.pass.cpp
new file mode 100644
index 00000000000000..5bf7aa526f0a26
--- /dev/null
+++ b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_signed_integer.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// Concept helpers for the internal type traits for the fundamental types.
+
+// template <class _Tp>
+// concept __libcpp_signed_integer;
+
+#include <concepts>
+
+#include "test_macros.h"
+
+struct SomeObject {};
+
+enum SomeEnum {};
+
+enum class SomeScopedEnum {};
+
+// Unsigned
+static_assert(!std::__libcpp_signed_integer<unsigned char>);
+static_assert(!std::__libcpp_signed_integer<unsigned short int>);
+static_assert(!std::__libcpp_signed_integer<unsigned int>);
+static_assert(!std::__libcpp_signed_integer<unsigned long int>);
+static_assert(!std::__libcpp_signed_integer<unsigned long long int>);
+static_assert(!std::__libcpp_signed_integer<unsigned short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(!std::__libcpp_signed_integer<__uint128_t>);
+#endif
+// Signed
+static_assert(std::__libcpp_signed_integer<signed char>);
+static_assert(std::__libcpp_signed_integer<short int>);
+static_assert(std::__libcpp_signed_integer<int>);
+static_assert(std::__libcpp_signed_integer<long int>);
+static_assert(std::__libcpp_signed_integer<long long int>);
+static_assert(std::__libcpp_signed_integer<short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_signed_integer<__int128_t>);
+#endif
+// Non-integer
+static_assert(!std::__libcpp_signed_integer<bool>);
+static_assert(!std::__libcpp_signed_integer<char>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::__libcpp_signed_integer<wchar_t>);
+#endif
+static_assert(!std::__libcpp_signed_integer<char8_t>);
+static_assert(!std::__libcpp_signed_integer<char16_t>);
+static_assert(!std::__libcpp_signed_integer<char32_t>);
+static_assert(!std::__libcpp_signed_integer<float>);
+static_assert(!std::__libcpp_signed_integer<double>);
+static_assert(!std::__libcpp_signed_integer<long double>);
+static_assert(!std::__libcpp_signed_integer<void>);
+static_assert(!std::__libcpp_signed_integer<int*>);
+static_assert(!std::__libcpp_signed_integer<unsigned int*>);
+static_assert(!std::__libcpp_signed_integer<SomeObject>);
+static_assert(!std::__libcpp_signed_integer<SomeEnum>);
+static_assert(!std::__libcpp_signed_integer<SomeScopedEnum>);
diff --git a/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_unsigned_integer.compile.pass.cpp b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_unsigned_integer.compile.pass.cpp
new file mode 100644
index 00000000000000..163ec53e17bc1e
--- /dev/null
+++ b/libcxx/test/libcxx/concepts/concepts.arithmetic/__libcpp_unsigned_integer.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// Concept helpers for the internal type traits for the fundamental types.
+
+// template <class _Tp>
+// concept __libcpp_unsigned_integer;
+
+#include <concepts>
+
+#include "test_macros.h"
+
+struct SomeObject {};
+
+enum SomeEnum {};
+
+enum class SomeScopedEnum {};
+
+// Unsigned
+static_assert(std::__libcpp_unsigned_integer<unsigned char>);
+static_assert(std::__libcpp_unsigned_integer<unsigned short int>);
+static_assert(std::__libcpp_unsigned_integer<unsigned int>);
+static_assert(std::__libcpp_unsigned_integer<unsigned long int>);
+static_assert(std::__libcpp_unsigned_integer<unsigned long long int>);
+static_assert(std::__libcpp_unsigned_integer<unsigned short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(std::__libcpp_unsigned_integer<__uint128_t>);
+#endif
+// Signed
+static_assert(!std::__libcpp_unsigned_integer<signed char>);
+static_assert(!std::__libcpp_unsigned_integer<short int>);
+static_assert(!std::__libcpp_unsigned_integer<int>);
+static_assert(!std::__libcpp_unsigned_integer<long int>);
+static_assert(!std::__libcpp_unsigned_integer<long long int>);
+static_assert(!std::__libcpp_unsigned_integer<short int>);
+#ifndef _LIBCPP_HAS_NO_INT128
+static_assert(!std::__libcpp_unsigned_integer<__int128_t>);
+#endif
+// Non-integer
+static_assert(!std::__libcpp_unsigned_integer<bool>);
+static_assert(!std::__libcpp_unsigned_integer<char>);
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+static_assert(!std::__libcpp_unsigned_integer<wchar_t>);
+#endif
+static_assert(!std::__libcpp_unsigned_integer<char8_t>);
+static_assert(!std::__libcpp_unsigned_integer<char16_t>);
+static_assert(!std::__libcpp_unsigned_integer<char32_t>);
+static_assert(!std::__libcpp_unsigned_integer<float>);
+static_assert(!std::__libcpp_unsigned_integer<double>);
+static_assert(!std::__libcpp_unsigned_integer<long double>);
+static_assert(!std::__libcpp_unsigned_integer<void>);
+static_assert(!std::__libcpp_unsigned_integer<int*>);
+static_assert(!std::__libcpp_unsigned_integer<unsigned int*>);
+static_assert(!std::__libcpp_unsigned_integer<SomeObject>);
+static_assert(!std::__libcpp_unsigned_integer<SomeEnum>);
+static_assert(!std::__libcpp_unsigned_integer<SomeScopedEnum>);
More information about the libcxx-commits
mailing list