[libcxx-commits] [libcxx] Speed up std::invoke() compile times by 50% (PR #213403)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 31 21:42:46 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h -- libcxx/include/__functional/invoke.h libcxx/include/__type_traits/invoke.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__type_traits/invoke.h b/libcxx/include/__type_traits/invoke.h
index 09a7b8105..7615af98e 100644
--- a/libcxx/include/__type_traits/invoke.h
+++ b/libcxx/include/__type_traits/invoke.h
@@ -21,9 +21,9 @@
#include <__type_traits/is_reference_wrapper.h>
#include <__type_traits/is_same.h>
#include <__type_traits/is_void.h>
+#include <__type_traits/nat.h>
#include <__type_traits/remove_cvref.h>
#include <__type_traits/type_identity.h>
-#include <__type_traits/nat.h>
#include <__type_traits/void_t.h>
#include <__utility/declval.h>
#include <__utility/forward.h>
@@ -269,7 +269,11 @@ template <class, class _Ret, class _Fp, class... _Args>
inline const bool __is_invocable_r_impl = false;
template <class _Ret, class _Fp, class... _Args>
-inline const bool __is_invocable_r_impl<decltype(void(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...))), _Ret, _Fp, _Args...> = is_void<_Ret>::value || __is_core_convertible<__sfinae_invoke_result_t<_Fp, _Args...>, _Ret>::value;
+inline const bool __is_invocable_r_impl<decltype(void(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...))),
+ _Ret,
+ _Fp,
+ _Args...> =
+ is_void<_Ret>::value || __is_core_convertible<__sfinae_invoke_result_t<_Fp, _Args...>, _Ret>::value;
template <class _Ret, class _Fp, class... _Args>
inline const bool __is_invocable_r_v = __is_invocable_r_impl<void, _Ret, _Fp, _Args...>;
@@ -287,17 +291,21 @@ template <bool _IsInvokable, class _Ret, class _Fp, class... _Args>
inline const bool __is_nothrow_invocable_r_v_imp = false;
template <class _Ret, class _Fp, class... _Args>
-inline const bool __is_nothrow_invocable_r_v_imp<true, _Ret, _Fp, _Args...> = noexcept(static_cast<void (*)(_Ret)>(0)(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...)));
+inline const bool __is_nothrow_invocable_r_v_imp<true, _Ret, _Fp, _Args...> =
+ noexcept(static_cast<void (*)(_Ret)>(0)(std::__invoke(std::declval<_Fp>(), std::declval<_Args>()...)));
template <class _Fp, class... _Args>
inline const bool __is_nothrow_invocable_r_v_imp<true, void, _Fp, _Args...> = __is_nothrow_invocable_v<_Fp, _Args...>;
template <class _Ret, class _Fp, class... _Args>
-inline const bool __is_nothrow_invocable_r_v _LIBCPP_NODEBUG = __is_nothrow_invocable_r_v_imp<__is_invocable_r_v<_Ret, _Fp, _Args...>, __conditional_t<is_void<_Ret>::value, void, _Ret>, _Fp, _Args...>;
+inline const bool __is_nothrow_invocable_r_v _LIBCPP_NODEBUG =
+ __is_nothrow_invocable_r_v_imp<__is_invocable_r_v<_Ret, _Fp, _Args...>,
+ __conditional_t<is_void<_Ret>::value, void, _Ret>,
+ _Fp,
+ _Args...>;
template <class _Func, class... _Args>
-struct __invoke_result
- : __type_identity<std::__sfinae_invoke_result_t<_Func, _Args...> > {};
+struct __invoke_result : __type_identity<std::__sfinae_invoke_result_t<_Func, _Args...> > {};
template <class _Func, class... _Args>
using __invoke_result_t _LIBCPP_NODEBUG = typename __invoke_result<_Func, _Args...>::type;
@@ -309,7 +317,7 @@ struct __is_invocable_r : integral_constant<bool, __is_invocable_r_v<_Ret, _Func
template <class _Ret, class... _Args>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Ret __invoke_r(_Args&&... __args)
- _NOEXCEPT_(noexcept(std::__invoke(std::forward<_Args>(__args)...))) {
+ _NOEXCEPT_(noexcept(std::__invoke(std::forward<_Args>(__args)...))) {
return std::__invoke(std::forward<_Args>(__args)...);
}
@@ -332,8 +340,7 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_invocable_r_v = __is_invocab
// is_nothrow_invocable
template <class _Fn, class... _Args>
-struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable
- : bool_constant<__is_nothrow_invocable_v<_Fn, _Args...> > {};
+struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable : bool_constant<__is_nothrow_invocable_v<_Fn, _Args...> > {};
template <class _Ret, class _Fn, class... _Args>
struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_invocable_r
@@ -350,7 +357,7 @@ template <class _Fn, class... _Args>
using invoke_result_t = __invoke_result_t<_Fn, _Args...>;
template <class _Fn, class... _Args>
-struct _LIBCPP_NO_SPECIALIZATIONS invoke_result : __type_identity<invoke_result_t<_Fn, _Args...> > {};
+struct _LIBCPP_NO_SPECIALIZATIONS invoke_result : __type_identity<invoke_result_t<_Fn, _Args...> > {};
#endif
``````````
</details>
https://github.com/llvm/llvm-project/pull/213403
More information about the libcxx-commits
mailing list