The Std::bind and function of c++11

Source: Internet
Author: User

  • Basic Test Code
      1. #include<iostream>
      2. #include<functional>
      3. void func(void)
      4. {
      5. std::cout << __FUNCTION__ << std::endl;
      6. }
      7. void callback(std::function<int(int,char*)> fr)
      8. {
      9. fr(1,"gdg");
      10. }
      11. int strlength(int n,constchar* str)
      12. {
      13. return n + strlen(str);
      14. }
      15. void outPut(int x,int y)
      16. {
      17. std::cout << x <<" "<< y << std::endl;
      18. }
      19. int main()
      20. {
      21. //测试bind
      22. auto fr = std::bind(strlength, std::placeholders::_1, std::placeholders::_2);
      23. //function作为函数参数
      24. callback(fr);
      25. std::bind(strlength,1,"hhha")();
      26. STD : bind ( Strlength std :: placeholders : _1 "HHA" 45 //the first parameter is passed out from the outside, the second parameter is already set
      27. STD : bind ( Strlength 23 STD : placeholders : _1 "Lallaa" //bind in the order of the parameters of the function
      28. STD : bind ( Strlength std :: placeholders : _2 STD : placeholders : _1 "HHAFDSF" 25 //the first argument with the passed-in second parameter, the second argument with the first parameter passed in
      29. std::bind(strlength, std::placeholders::_1, std::placeholders::_3)(12,45,"fhsafdf");//对,第二个参数没用到
      30. }



From for notes (Wiz)



The Std::bind and function of c++11

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.