[libcxx-commits] [libcxx] 2c10664 - [libc++][NFC] Merge add_{const, cv, volatile}.h into a single header (#115610)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 10 04:21:45 PST 2024


Author: Nikolas Klauser
Date: 2024-11-10T13:21:42+01:00
New Revision: 2c10664afafcd5915ebbde9cb7cb0e9cf8751b34

URL: https://github.com/llvm/llvm-project/commit/2c10664afafcd5915ebbde9cb7cb0e9cf8751b34
DIFF: https://github.com/llvm/llvm-project/commit/2c10664afafcd5915ebbde9cb7cb0e9cf8751b34.diff

LOG: [libc++][NFC] Merge add_{const, cv, volatile}.h into a single header (#115610)

There isn't much benefit in having granular headers for only a few
simple lines of code.

Added: 
    libcxx/include/__type_traits/add_cv_quals.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/__type_traits/is_trivially_assignable.h
    libcxx/include/__utility/as_const.h
    libcxx/include/any
    libcxx/include/module.modulemap
    libcxx/include/type_traits
    libcxx/include/variant

Removed: 
    libcxx/include/__type_traits/add_const.h
    libcxx/include/__type_traits/add_cv.h
    libcxx/include/__type_traits/add_volatile.h


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index ae2e8bcb32aaa4..938d0bb872e0b5 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -738,12 +738,10 @@ set(files
   __tuple/tuple_like_no_subrange.h
   __tuple/tuple_size.h
   __tuple/tuple_types.h
-  __type_traits/add_const.h
-  __type_traits/add_cv.h
+  __type_traits/add_cv_quals.h
   __type_traits/add_lvalue_reference.h
   __type_traits/add_pointer.h
   __type_traits/add_rvalue_reference.h
-  __type_traits/add_volatile.h
   __type_traits/aligned_storage.h
   __type_traits/aligned_union.h
   __type_traits/alignment_of.h

diff  --git a/libcxx/include/__type_traits/add_const.h b/libcxx/include/__type_traits/add_const.h
deleted file mode 100644
index 9a6f1c10299f7f..00000000000000
--- a/libcxx/include/__type_traits/add_const.h
+++ /dev/null
@@ -1,32 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___TYPE_TRAITS_ADD_CONST_H
-#define _LIBCPP___TYPE_TRAITS_ADD_CONST_H
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS add_const {
-  typedef _LIBCPP_NODEBUG const _Tp type;
-};
-
-#if _LIBCPP_STD_VER >= 14
-template <class _Tp>
-using add_const_t = typename add_const<_Tp>::type;
-#endif
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___TYPE_TRAITS_ADD_CONST_H

diff  --git a/libcxx/include/__type_traits/add_cv.h b/libcxx/include/__type_traits/add_cv_quals.h
similarity index 66%
rename from libcxx/include/__type_traits/add_cv.h
rename to libcxx/include/__type_traits/add_cv_quals.h
index 9e23e5ceb7a3bd..1d35b89f42c2d1 100644
--- a/libcxx/include/__type_traits/add_cv.h
+++ b/libcxx/include/__type_traits/add_cv_quals.h
@@ -17,6 +17,16 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+template <class _Tp>
+struct _LIBCPP_TEMPLATE_VIS add_const {
+  typedef _LIBCPP_NODEBUG const _Tp type;
+};
+
+#if _LIBCPP_STD_VER >= 14
+template <class _Tp>
+using add_const_t = typename add_const<_Tp>::type;
+#endif
+
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS add_cv {
   typedef _LIBCPP_NODEBUG const volatile _Tp type;
@@ -27,6 +37,16 @@ template <class _Tp>
 using add_cv_t = typename add_cv<_Tp>::type;
 #endif
 
+template <class _Tp>
+struct _LIBCPP_TEMPLATE_VIS add_volatile {
+  typedef _LIBCPP_NODEBUG volatile _Tp type;
+};
+
+#if _LIBCPP_STD_VER >= 14
+template <class _Tp>
+using add_volatile_t = typename add_volatile<_Tp>::type;
+#endif
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H

diff  --git a/libcxx/include/__type_traits/add_volatile.h b/libcxx/include/__type_traits/add_volatile.h
deleted file mode 100644
index 56b7dfaac026e7..00000000000000
--- a/libcxx/include/__type_traits/add_volatile.h
+++ /dev/null
@@ -1,32 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
-#define _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS add_volatile {
-  typedef _LIBCPP_NODEBUG volatile _Tp type;
-};
-
-#if _LIBCPP_STD_VER >= 14
-template <class _Tp>
-using add_volatile_t = typename add_volatile<_Tp>::type;
-#endif
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___TYPE_TRAITS_ADD_VOLATILE_H

diff  --git a/libcxx/include/__type_traits/is_trivially_assignable.h b/libcxx/include/__type_traits/is_trivially_assignable.h
index 201333b0fa0b33..7720c3e637506a 100644
--- a/libcxx/include/__type_traits/is_trivially_assignable.h
+++ b/libcxx/include/__type_traits/is_trivially_assignable.h
@@ -10,7 +10,6 @@
 #define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_ASSIGNABLE_H
 
 #include <__config>
-#include <__type_traits/add_const.h>
 #include <__type_traits/add_lvalue_reference.h>
 #include <__type_traits/add_rvalue_reference.h>
 #include <__type_traits/integral_constant.h>

diff  --git a/libcxx/include/__utility/as_const.h b/libcxx/include/__utility/as_const.h
index 582dd42f407915..0f54b984725c60 100644
--- a/libcxx/include/__utility/as_const.h
+++ b/libcxx/include/__utility/as_const.h
@@ -10,9 +10,6 @@
 #define _LIBCPP___UTILITY_AS_CONST_H
 
 #include <__config>
-#include <__type_traits/add_const.h>
-#include <__utility/forward.h>
-#include <__utility/move.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -22,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 17
 template <class _Tp>
-[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept {
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& as_const(_Tp& __t) noexcept {
   return __t;
 }
 

diff  --git a/libcxx/include/any b/libcxx/include/any
index e32aa7f8e8a420..719dc2cf999e50 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -85,7 +85,7 @@ namespace std {
 #include <__memory/allocator_destructor.h>
 #include <__memory/allocator_traits.h>
 #include <__memory/unique_ptr.h>
-#include <__type_traits/add_const.h>
+#include <__type_traits/add_cv_quals.h>
 #include <__type_traits/add_pointer.h>
 #include <__type_traits/aligned_storage.h>
 #include <__type_traits/conditional.h>

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 6b0cc07fca0787..5465d603b2c4d0 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -63,12 +63,10 @@ module std_core [system] {
   }
 
   module type_traits {
-    module add_const                                  { header "__type_traits/add_const.h" }
-    module add_cv                                     { header "__type_traits/add_cv.h" }
+    module add_cv_quals                               { header "__type_traits/add_cv_quals.h" }
     module add_lvalue_reference                       { header "__type_traits/add_lvalue_reference.h" }
     module add_pointer                                { header "__type_traits/add_pointer.h" }
     module add_rvalue_reference                       { header "__type_traits/add_rvalue_reference.h" }
-    module add_volatile                               { header "__type_traits/add_volatile.h" }
     module aligned_storage                            { header "__type_traits/aligned_storage.h" }
     module aligned_union                              { header "__type_traits/aligned_union.h" }
     module alignment_of                               { header "__type_traits/alignment_of.h" }

diff  --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index baeed35ca8508b..cc2b7511d24d3b 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -425,12 +425,10 @@ namespace std
 */
 
 #include <__config>
-#include <__type_traits/add_const.h>
-#include <__type_traits/add_cv.h>
+#include <__type_traits/add_cv_quals.h>
 #include <__type_traits/add_lvalue_reference.h>
 #include <__type_traits/add_pointer.h>
 #include <__type_traits/add_rvalue_reference.h>
-#include <__type_traits/add_volatile.h>
 #include <__type_traits/aligned_storage.h>
 #include <__type_traits/aligned_union.h>
 #include <__type_traits/alignment_of.h>

diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 6e752556a888dd..f604527cd22569 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -226,10 +226,8 @@ namespace std {
 #include <__memory/construct_at.h>
 #include <__tuple/find_index.h>
 #include <__tuple/sfinae_helpers.h>
-#include <__type_traits/add_const.h>
-#include <__type_traits/add_cv.h>
+#include <__type_traits/add_cv_quals.h>
 #include <__type_traits/add_pointer.h>
-#include <__type_traits/add_volatile.h>
 #include <__type_traits/common_type.h>
 #include <__type_traits/conditional.h>
 #include <__type_traits/conjunction.h>


        


More information about the libcxx-commits mailing list