Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ - use more expressive std::any_of rather than std::find
What's looked for is encapsulated in a lambda function named is_req_column_type. This compares values in the vector with a value captured from the main context, which is updated for each call of std::any.
- Loading branch information
Showing
1 changed file
with
9 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16cc218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a functional programming pov I get nervous with the varying
req_column_type
! I'd write as:16cc218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that looks better in this case. Feel free to submit a fix.
16cc218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the wrapper lambda there's no reason to capture
req_column_type
by reference in the inner lambda.16cc218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it was never needed to capture by reference. But for clarity, we still have to capture it, no ? Is there another way to pass it to the inner lambda ?
16cc218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as it is now it does need to capture by reference. A lambda is a closure and the capture happens at the point that the lambda is created, in this case when it's assigned to
is_req_column_type
and if it capturedreq_column_type
by value it would get whatever garbage happened to be there.