[libcxx-commits] [libcxx] Speed up compilation of common uses of std::visit() by ~8x (PR #164196)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 19 19:16:06 PDT 2025


================
@@ -1578,11 +1578,42 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __throw_if_valueless(_Vs&&... __vs) {
   }
 }
 
-template < class _Visitor, class... _Vs, typename>
+template <class _Visitor, class... _Vs, typename>
 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
-  using __variant_detail::__visitation::__variant;
-  std::__throw_if_valueless(std::forward<_Vs>(__vs)...);
-  return __variant::__visit_value(std::forward<_Visitor>(__visitor), std::forward<_Vs>(__vs)...);
+#    define _XDispatchIndex(_I)                                                                                        \
----------------
frederick-vs-ja wrote:

Looks like that we can use the same technique for for `visit<R>` overload added in C++20.

https://github.com/llvm/llvm-project/pull/164196


More information about the libcxx-commits mailing list