Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement parameter binding in Category 11

Shulou Source: shulou.com Published: 2022-06-02 07:55:41 11月15日 Update

Many beginners are not very clear about how to implement parameter binding in Category 11. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Disadvantages of lambda expressions

Remember why lambda expressions were introduced in the first place? When passing predicates to the algorithm, because the general function can not transfer information other than parameters, and the function object is more troublesome, so the lambda expression is introduced.

But lambda expressions also have a drawback: defining lambada expressions each time can be cumbersome when similar features are used many times. This article introduces another approach: parameter binding.

Standard library bind function

Continuing with the examples used in the lambda expression, if you want to find the first string with a length less than 2, you can use the following code:

Bool istarget (const string& s) {

Return s.size () < 2

}

Vector v {"This", "is", "a", "predicate", "."}

Auto found = find_if (v.begin (), v.end (), istarget)

Cout

Tags: Parameters functions objects expressions adjustable standard length requirements consistency information variables location that is form time algorithm shortcomings trouble help adaptation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology vpn Docker macOS