[libc][NFC] Use STL case for utility
Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.
Differential Revision: https://reviews.llvm.org/D130771
GitOrigin-RevId: 49eb58063f2422fb0cd067c05d3c184b42243630
diff --git a/src/__support/CPP/CMakeLists.txt b/src/__support/CPP/CMakeLists.txt
index 4897154..ff9ae5f 100644
--- a/src/__support/CPP/CMakeLists.txt
+++ b/src/__support/CPP/CMakeLists.txt
@@ -79,7 +79,7 @@
add_header_library(
utility
HDRS
- Utility.h
+ utility.h
)
add_header_library(
diff --git a/src/__support/CPP/Utility.h b/src/__support/CPP/utility.h
similarity index 61%
rename from src/__support/CPP/Utility.h
rename to src/__support/CPP/utility.h
index 00805c7..52044eb 100644
--- a/src/__support/CPP/Utility.h
+++ b/src/__support/CPP/utility.h
@@ -13,26 +13,27 @@
namespace __llvm_libc::cpp {
-template <typename T, T... Seq> struct IntegerSequence {
+template <typename T, T... Ints> struct integer_sequence {
static_assert(is_integral_v<T>);
- template <T Next> using append = IntegerSequence<T, Seq..., Next>;
+ template <T Next> using append = integer_sequence<T, Ints..., Next>;
};
namespace internal {
-template <typename T, int N> struct MakeIntegerSequence {
- using type = typename MakeIntegerSequence<T, N - 1>::type::template append<N>;
+template <typename T, int N> struct make_integer_sequence {
+ using type =
+ typename make_integer_sequence<T, N - 1>::type::template append<N>;
};
-template <typename T> struct MakeIntegerSequence<T, -1> {
- using type = IntegerSequence<T>;
+template <typename T> struct make_integer_sequence<T, -1> {
+ using type = integer_sequence<T>;
};
} // namespace internal
template <typename T, int N>
-using MakeIntegerSequence =
- typename internal::MakeIntegerSequence<T, N - 1>::type;
+using make_integer_sequence =
+ typename internal::make_integer_sequence<T, N - 1>::type;
} // namespace __llvm_libc::cpp
diff --git a/test/src/__support/CPP/integer_sequence_test.cpp b/test/src/__support/CPP/integer_sequence_test.cpp
index 6cee9dd..e84f390 100644
--- a/test/src/__support/CPP/integer_sequence_test.cpp
+++ b/test/src/__support/CPP/integer_sequence_test.cpp
@@ -6,23 +6,24 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/Utility.h"
+#include "src/__support/CPP/utility.h"
#include "utils/UnitTest/Test.h"
using namespace __llvm_libc::cpp;
TEST(LlvmLibcIntegerSequencetTest, Basic) {
- EXPECT_TRUE((is_same_v<IntegerSequence<int>, MakeIntegerSequence<int, 0>>));
- using ISeq = IntegerSequence<int, 0, 1, 2, 3>;
- EXPECT_TRUE((is_same_v<ISeq, MakeIntegerSequence<int, 4>>));
- using LSeq = IntegerSequence<long, 0, 1, 2, 3>;
- EXPECT_TRUE((is_same_v<LSeq, MakeIntegerSequence<long, 4>>));
- using ULLSeq = IntegerSequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>;
- EXPECT_TRUE((is_same_v<ULLSeq, MakeIntegerSequence<unsigned long long, 4>>));
+ EXPECT_TRUE(
+ (is_same_v<integer_sequence<int>, make_integer_sequence<int, 0>>));
+ using ISeq = integer_sequence<int, 0, 1, 2, 3>;
+ EXPECT_TRUE((is_same_v<ISeq, make_integer_sequence<int, 4>>));
+ using LSeq = integer_sequence<long, 0, 1, 2, 3>;
+ EXPECT_TRUE((is_same_v<LSeq, make_integer_sequence<long, 4>>));
+ using ULLSeq = integer_sequence<unsigned long long, 0ull, 1ull, 2ull, 3ull>;
+ EXPECT_TRUE(
+ (is_same_v<ULLSeq, make_integer_sequence<unsigned long long, 4>>));
}
-template <typename T, T... Ts>
-bool checkArray(IntegerSequence<T, Ts...> seq) {
+template <typename T, T... Ts> bool checkArray(integer_sequence<T, Ts...> seq) {
T arr[sizeof...(Ts)]{Ts...};
for (T i = 0; i < static_cast<T>(sizeof...(Ts)); i++)
@@ -33,5 +34,5 @@
}
TEST(LlvmLibcIntegerSequencetTest, Many) {
- EXPECT_TRUE(checkArray(MakeIntegerSequence<int, 100>{}));
+ EXPECT_TRUE(checkArray(make_integer_sequence<int, 100>{}));
}
diff --git a/test/src/stdlib/atexit_test.cpp b/test/src/stdlib/atexit_test.cpp
index 11ab2fa..21ecefa 100644
--- a/test/src/stdlib/atexit_test.cpp
+++ b/test/src/stdlib/atexit_test.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/Utility.h"
#include "src/__support/CPP/array.h"
+#include "src/__support/CPP/utility.h"
#include "src/stdlib/atexit.h"
#include "src/stdlib/exit.h"
#include "utils/UnitTest/Test.h"
@@ -43,7 +43,7 @@
static __llvm_libc::cpp::array<int, 256> arr;
template <int... Ts>
-void register_atexit_handlers(__llvm_libc::cpp::IntegerSequence<int, Ts...>) {
+void register_atexit_handlers(__llvm_libc::cpp::integer_sequence<int, Ts...>) {
(__llvm_libc::atexit(+[] { arr[size++] = Ts; }), ...);
}
@@ -57,7 +57,7 @@
__builtin_trap();
});
register_atexit_handlers(
- __llvm_libc::cpp::MakeIntegerSequence<int, count>{});
+ __llvm_libc::cpp::make_integer_sequence<int, count>{});
__llvm_libc::exit(0);
};
}