Skip to content

refactor: prefer lambda to bind.#1157

Open
Dragonliu2018 wants to merge 1 commit intojd-opensource:mainfrom
Dragonliu2018:lzl/refactor/prefer_lambdas
Open

refactor: prefer lambda to bind.#1157
Dragonliu2018 wants to merge 1 commit intojd-opensource:mainfrom
Dragonliu2018:lzl/refactor/prefer_lambdas

Conversation

@Dragonliu2018
Copy link
Copy Markdown
Contributor

Replace std::bind with lambdas following "Effective Modern C++" Item 34 guidelines.

Item 34: Prefer lambdas to std::bind.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +150 to +151
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +178 to +179
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +218 to +219
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +245 to +246
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +447 to +448
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +467 to +468
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +522 to +523
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +588 to +589
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +633 to +634
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

Comment on lines +833 to +834
[] { request_in_metric(nullptr); },
[controller] { request_out_metric(static_cast<void*>(controller)); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
[] { 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
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

@XuZhang99
Copy link
Copy Markdown
Collaborator

XuZhang99 commented Apr 1, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants