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

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 19 19:35:42 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)                                                                                        \
----------------
higher-performance wrote:

Yeah, I deliberately avoided doing more work to make it easier to review and get feedback first. It adds edge cases to testing so I'm not sure how folks feel about it.

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


More information about the libcxx-commits mailing list