refactor: prefer lambda to bind.#1157
refactor: prefer lambda to bind.#1157Dragonliu2018 wants to merge 1 commit intojd-opensource:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces std::bind with lambdas across APIService and XServiceClient to modernize the codebase. Feedback was provided regarding signature mismatches in the lambdas used with ClosureGuard in api_service.cpp, which require a void* parameter to be compatible. Additionally, constant arguments such as nullptr should be annotated with their parameter names to comply with the repository's style guide.
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
| [] { request_in_metric(nullptr); }, | ||
| [controller] { request_out_metric(static_cast<void*>(controller)); }); |
There was a problem hiding this comment.
The lambdas passed to ClosureGuard must match the signature std::function<void(void*)>. Unlike std::bind results, lambdas do not automatically ignore extra arguments. Thus, a lambda with signature void() cannot be assigned to std::function<void(void*)>. You must add a void* parameter to the lambdas to ensure compatibility. Additionally, per the Repository Style Guide (Line 260), constant arguments like nullptr should be annotated with the parameter name.
| [] { request_in_metric(nullptr); }, | |
| [controller] { request_out_metric(static_cast<void*>(controller)); }); | |
| [](void*) { request_in_metric(nullptr); }, | |
| [controller](void*) { request_out_metric(static_cast<void*>(controller)); }); |
References
- Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)
|
please add this style to https://github.com/jd-opensource/xllm/blob/main/.agent/skills/code-review/references/custom-code-style.md, following other code-style format. |
Replace std::bind with lambdas following "Effective Modern C++" Item 34 guidelines.