[libc-commits] [libc] 49eb580 - [libc][NFC] Use STL case for utility

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Mon Aug 1 02:29:21 PDT 2022


Author: Guillaume Chatelet
Date: 2022-08-01T09:27:37Z
New Revision: 49eb58063f2422fb0cd067c05d3c184b42243630

URL: https://github.com/llvm/llvm-project/commit/49eb58063f2422fb0cd067c05d3c184b42243630
DIFF: https://github.com/llvm/llvm-project/commit/49eb58063f2422fb0cd067c05d3c184b42243630.diff

LOG: [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

Added: 
    libc/src/__support/CPP/utility.h

Modified: 
    libc/src/__support/CPP/CMakeLists.txt
    libc/test/src/__support/CPP/integer_sequence_test.cpp
    libc/test/src/stdlib/atexit_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    libc/src/__support/CPP/Utility.h


################################################################################
diff  --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index 489715400395b..ff9ae5f7d9f47 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -79,7 +79,7 @@ add_header_library(
 add_header_library(
   utility
   HDRS
-    Utility.h
+    utility.h
 )
 
 add_header_library(

diff  --git a/libc/src/__support/CPP/Utility.h b/libc/src/__support/CPP/utility.h
similarity index 61%
rename from libc/src/__support/CPP/Utility.h
rename to libc/src/__support/CPP/utility.h
index 00805c79ce7a0..52044eb0b9b72 100644
--- a/libc/src/__support/CPP/Utility.h
+++ b/libc/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/libc/test/src/__support/CPP/integer_sequence_test.cpp b/libc/test/src/__support/CPP/integer_sequence_test.cpp
index 6cee9dd9aa135..e84f390e20523 100644
--- a/libc/test/src/__support/CPP/integer_sequence_test.cpp
+++ b/libc/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 @@ bool checkArray(IntegerSequence<T, Ts...> seq) {
 }
 
 TEST(LlvmLibcIntegerSequencetTest, Many) {
-  EXPECT_TRUE(checkArray(MakeIntegerSequence<int, 100>{}));
+  EXPECT_TRUE(checkArray(make_integer_sequence<int, 100>{}));
 }

diff  --git a/libc/test/src/stdlib/atexit_test.cpp b/libc/test/src/stdlib/atexit_test.cpp
index 11ab2fa690403..21ecefac07f54 100644
--- a/libc/test/src/stdlib/atexit_test.cpp
+++ b/libc/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 int size;
 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 @@ template <int count> constexpr auto getTest() {
           __builtin_trap();
     });
     register_atexit_handlers(
-        __llvm_libc::cpp::MakeIntegerSequence<int, count>{});
+        __llvm_libc::cpp::make_integer_sequence<int, count>{});
     __llvm_libc::exit(0);
   };
 }

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 7cf8e33d364c5..607a4c0f866f6 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -107,7 +107,7 @@ cc_library(
 
 cc_library(
     name = "__support_cpp_utility",
-    hdrs = ["src/__support/CPP/Utility.h"],
+    hdrs = ["src/__support/CPP/utility.h"],
     deps = [
         ":__support_cpp_type_traits",
         ":libc_root",


        


More information about the libc-commits mailing list