fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct some_class
  6. {
  7. char field1;
  8. bool field2;
  9.  
  10. some_class()
  11. : field1('a')
  12. , field2(0)
  13. {
  14. }
  15. };
  16.  
  17. struct unnamed_lambda
  18. {
  19. template<typename T>
  20. T operator()(T x) const { return x + 1; }
  21. };
  22.  
  23. struct unnamed_lambda2
  24. {
  25. template<typename T>
  26. T operator()(T x) const { return x + 2; }
  27. };
  28.  
  29.  
  30. template<class processor>
  31. void reflect(processor & p, some_class& sc)
  32. {
  33. reflect(p, sc.field1, "field1");
  34. reflect(p, sc.field2, "field2");
  35. }
  36.  
  37. template<class t>
  38. void reflect(unnamed_lambda & p, t& val, string str)
  39. {
  40. cout << val << endl;
  41. }
  42.  
  43. void print_helper()
  44. {
  45. unnamed_lambda lambda = unnamed_lambda{};
  46. some_class sc;
  47.  
  48. reflect(lambda, sc);
  49. }
  50.  
  51. template<class t>
  52. void reflect2(unnamed_lambda2 & p, t& val, string str)
  53. {
  54. cout << val + 1 << endl;
  55. }
  56.  
  57. void print_helper2()
  58. {
  59. unnamed_lambda2 lambda = unnamed_lambda2{};
  60. some_class sc;
  61.  
  62. reflect(lambda, sc);
  63. }
  64.  
  65.  
  66. int main()
  67. {
  68. print_helper();
  69. print_helper2();
  70.  
  71. system("pause");
  72.  
  73. return 0;
  74. }
  75.  
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'void reflect(processor&, some_class&) [with processor = unnamed_lambda2]':
prog.cpp:62:23:   required from here
prog.cpp:33:35: error: no matching function for call to 'reflect(unnamed_lambda2&, char&, const char [7])'
     reflect(p, sc.field1, "field1");
                                   ^
prog.cpp:33:35: note: candidates are:
prog.cpp:31:6: note: template<class processor> void reflect(processor&, some_class&)
 void reflect(processor & p, some_class& sc)
      ^
prog.cpp:31:6: note:   template argument deduction/substitution failed:
prog.cpp:33:35: note:   cannot convert 'sc.some_class::field1' (type 'char') to type 'some_class&'
     reflect(p, sc.field1, "field1");
                                   ^
prog.cpp:38:6: note: template<class t> void reflect(unnamed_lambda&, t&, std::string)
 void reflect(unnamed_lambda & p, t& val, string str)
      ^
prog.cpp:38:6: note:   template argument deduction/substitution failed:
prog.cpp:33:35: note:   cannot convert 'p' (type 'unnamed_lambda2') to type 'unnamed_lambda&'
     reflect(p, sc.field1, "field1");
                                   ^
prog.cpp:34:35: error: no matching function for call to 'reflect(unnamed_lambda2&, bool&, const char [7])'
     reflect(p, sc.field2, "field2");
                                   ^
prog.cpp:34:35: note: candidates are:
prog.cpp:31:6: note: template<class processor> void reflect(processor&, some_class&)
 void reflect(processor & p, some_class& sc)
      ^
prog.cpp:31:6: note:   template argument deduction/substitution failed:
prog.cpp:34:35: note:   cannot convert 'sc.some_class::field2' (type 'bool') to type 'some_class&'
     reflect(p, sc.field2, "field2");
                                   ^
prog.cpp:38:6: note: template<class t> void reflect(unnamed_lambda&, t&, std::string)
 void reflect(unnamed_lambda & p, t& val, string str)
      ^
prog.cpp:38:6: note:   template argument deduction/substitution failed:
prog.cpp:34:35: note:   cannot convert 'p' (type 'unnamed_lambda2') to type 'unnamed_lambda&'
     reflect(p, sc.field2, "field2");
                                   ^
stdout
Standard output is empty