fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. // ==========================
  6. template <typename F>
  7. void apply(F&&) {}
  8.  
  9. template <typename F, typename First, typename... Rest>
  10. void apply(F&& f, First&& first, Rest&&... rest) {
  11. std::forward<F>(f)(std::forward<First>(first));
  12.  
  13. apply(std::forward<F>(f), std::forward<Rest>(rest)...);
  14. }
  15. // ==========================
  16.  
  17.  
  18.  
  19. class A{
  20. public:
  21. int x, y, z;
  22.  
  23. A() {
  24. this->x = 0;
  25. this->y = 0;
  26. this->z = 0;
  27. }
  28.  
  29. ~A() { }
  30.  
  31. void init (int x_in, int y_in, int z_in){
  32. this->x = x_in;
  33. this->y = y_in;
  34. this->z = z_in;
  35. }
  36.  
  37. int sum(){
  38. return this->x + this->y + this->z;
  39. }
  40.  
  41. void show_result() {
  42. int result = sum();
  43. cout << "sum = " << result << endl;
  44. }
  45. };
  46.  
  47.  
  48.  
  49. #define PP_MEMBER_LIST A_CAR, A_CAT, A_CANADA
  50.  
  51. class B {
  52. public:
  53. A PP_MEMBER_LIST;
  54.  
  55. B() {
  56. A_CAR.init(0, 1, 2);
  57. A_CAT.init(1, 2, 3);
  58. A_CANADA.init(8, 7, 6);
  59. }
  60.  
  61. ~B() {}
  62.  
  63. void show_all_result() {
  64. const auto show_result = [](A& a) { a.show_result(); };
  65.  
  66. apply(show_result, PP_MEMBER_LIST);
  67. }
  68. };
  69.  
  70.  
  71. int main() {
  72.  
  73. B obj_B;
  74.  
  75. obj_B.show_all_result();
  76. }
  77.  
Success #stdin #stdout 0s 4184KB
stdin
Standard input is empty
stdout
sum = 3
sum = 6
sum = 21