Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement parameter binding in Category 11

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report