Test Loki in WinCE (wm5.0 PPC) -- functor

Source: Internet
Author: User
This article demonstrates a test example of the Loki functor template class in the wince environment. It mainly demonstrates the usage of the following functor:
  • Use the function to initialize LOKI: functor
  • Use functor to initialize LOKI: functor
  • Use the class member function to initialize LOKI: functor
  • Use other LOKI: functor to initialize LOKI: functor
  • LOKI: functor

These examples are mainly derived from the example code in the book (modern c ++ design), I added some implementation code, as well as adaptive modifications to the Loki-0.1.6 version. Go to sf.net to download the Loki-0.1.6 (the latest version ).

The following shows the sample code:

  1. # Include "stdafx. H "//
  2. # Include <Loki/functor. h>
  3. # Include <Loki/typelistmacros. h>
  4. # Include <iostream>
  5. // Using namespace Loki;
  6. // A function
  7. Void function (INT m)
  8. {
  9. STD: cout <"Void function (" <m <");" <STD: Endl;
  10. }
  11. // A functor
  12. Struct somefunctor {
  13. Void operator () (INT m ){
  14. STD: cout <"somfunction: Operator () (" <m <");" <STD: Endl;
  15. }
  16. };
  17. // A class member function
  18. Struct someclass {
  19. Void memberfunction (INT m ){
  20. STD: cout <"someclass: memberfunction (" <m <");" <STD: Endl;
  21. }
  22. };
  23. Void testfunctors ()
  24. {
  25. // Initialize with a function
  26. LOKI: functor <void, loki_typelist_1 (INT)> cmd1 (function );
  27. // Initialize with a functor
  28. Somefunctor FN;
  29. LOKI: functor <void, loki_typelist_1 (INT)> cmd2 (FN );
  30. // Initialize with a pointer to member function
  31. // And a pointer to member function
  32. Someclass myobject;
  33. LOKI: functor <void, loki_typelist_1 (INT)> cmd3 (& myobject, & someclass: memberfunction );
  34. // Initialize a functor with another
  35. // (Copying)
  36. LOKI: functor <void, loki_typelist_1 (INT)> limit 4 (cmd3 );
  37. LOKI: functor <void, loki_typelist_1 (INT)> lifecycle 5 (chain (cmd1, cmd2 ));
  38. // Run
  39. STD: cout <"Call cmd1 ()..." <STD: Endl;
  40. Cmd1 (1 );
  41. STD: cout <"Call cmd2 ()..." <STD: Endl;
  42. Cmd2 (2 );
  43. STD: cout <"Call cmd3 ()..." <STD: Endl;
  44. Cmd3 (3 );
  45. STD: cout <"Call done 4 ()..." <STD: Endl;
  46. Limit 4 (4 );
  47. STD: cout <"Call done 5 ()..." <STD: Endl;
  48. Limit 5 (5 );
  49. }

The running result is as follows:

Call cmd1 ()...
Void function (1 );
Call cmd2 ()...
Somfunction: Operator () (2 );
Call cmd3 ()...
Someclass: memberfunction (3 );
Call limit 4 ()...
Someclass: memberfunction (4 );
Call limit 5 ()...
Void function (5 );
Somfunction: Operator () (5 );

The above example is run in the simulator. Since the instruction set (instructionset) has been specified as armvi during compilation, I believe it can also be run on the real machine.

In addition, Versions later than s60 3rd ed support openc/C ++, and the testing results under Symbian (simulator/real machine) will be displayed when the value is blank in a period of time ).

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.