[libcxx-commits] [libcxx] [libc++] Simplify some meta programming in <variant> (PR #201538)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 4 02:17:49 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/201538
Specifically, this avoids `__dependent_type` and `__type_identity` instantiations, reducing compile times a bit.
>From 9c9114a6c764c7e1c6b463a54be5ddf8e3b4d228 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 4 Jun 2026 10:49:27 +0200
Subject: [PATCH] [libc++] Simplify some meta programming in <variant>
---
libcxx/include/CMakeLists.txt | 1 -
libcxx/include/__type_traits/dependent_type.h | 25 -------------------
libcxx/include/module.modulemap.in | 1 -
libcxx/include/variant | 15 ++++++-----
4 files changed, 7 insertions(+), 35 deletions(-)
delete mode 100644 libcxx/include/__type_traits/dependent_type.h
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 10dfb4b4d58cb..e1da7aa279778 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -826,7 +826,6 @@ set(files
__type_traits/copy_cvref.h
__type_traits/datasizeof.h
__type_traits/decay.h
- __type_traits/dependent_type.h
__type_traits/desugars_to.h
__type_traits/detected_or.h
__type_traits/disjunction.h
diff --git a/libcxx/include/__type_traits/dependent_type.h b/libcxx/include/__type_traits/dependent_type.h
deleted file mode 100644
index 354705c49c90e..0000000000000
--- a/libcxx/include/__type_traits/dependent_type.h
+++ /dev/null
@@ -1,25 +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_DEPENDENT_TYPE_H
-#define _LIBCPP___TYPE_TRAITS_DEPENDENT_TYPE_H
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _Tp, bool>
-struct __dependent_type : public _Tp {};
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___TYPE_TRAITS_DEPENDENT_TYPE_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 2ccb455b7408d..0b141ecda1258 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -90,7 +90,6 @@ module std_core [system] {
module copy_cvref { header "__type_traits/copy_cvref.h" }
module datasizeof { header "__type_traits/datasizeof.h" }
module decay { header "__type_traits/decay.h" }
- module dependent_type { header "__type_traits/dependent_type.h" }
module desugars_to { header "__type_traits/desugars_to.h" }
module detected_or { header "__type_traits/detected_or.h" }
module disjunction { header "__type_traits/disjunction.h" }
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 45462ee8a7713..95c93b814fbb8 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -235,7 +235,6 @@ namespace std {
# include <__type_traits/conditional.h>
# include <__type_traits/conjunction.h>
# include <__type_traits/decay.h>
-# include <__type_traits/dependent_type.h>
# include <__type_traits/enable_if.h>
# include <__type_traits/invoke.h>
# include <__type_traits/is_array.h>
@@ -541,9 +540,12 @@ private:
return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
}
+ template <class, class _Tp>
+ using __expander = _Tp;
+
template <size_t _Ip, class _Fp, class... _Vs>
_LIBCPP_HIDE_FROM_ABI static constexpr auto __make_fdiagonal_impl() {
- return __make_dispatch<_Fp, _Vs...>(index_sequence<((void)__type_identity<_Vs>{}, _Ip)...>{});
+ return __make_dispatch<_Fp, _Vs...>(index_sequence<static_cast<__expander<_Vs, size_t>>(_Ip)...>{});
}
template <class _Fp, class... _Vs, size_t... _Is>
@@ -1167,8 +1169,7 @@ public:
using __trivially_relocatable _LIBCPP_NODEBUG =
conditional_t<_And<__libcpp_is_trivially_relocatable<_Types>...>::value, variant, void>;
- template <bool _Dummy = true,
- enable_if_t<__dependent_type<is_default_constructible<__first_type>, _Dummy>::value, int> = 0>
+ template <class _FirstType = __first_type, enable_if_t<is_default_constructible_v<_FirstType>, int> = 0>
_LIBCPP_HIDE_FROM_ABI constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>)
: __impl_(in_place_index<0>) {}
@@ -1283,10 +1284,8 @@ public:
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr size_t index() const noexcept { return __impl_.index(); }
- template < bool _Dummy = true,
- enable_if_t< __all<(__dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
- __dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,
- int> = 0>
+ template <bool _Dummy = true,
+ enable_if_t<__all<_Dummy, (is_move_constructible_v<_Types> && is_swappable_v<_Types>)...>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(variant& __that) noexcept(
__all<(is_nothrow_move_constructible_v<_Types> && is_nothrow_swappable_v<_Types>)...>::value) {
__impl_.__swap(__that.__impl_);
More information about the libcxx-commits
mailing list