fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <type_traits>
  4.  
  5. struct A {
  6. int x;
  7.  
  8. void a() {
  9. std::cout << "an a! " << x << "\n";
  10. }
  11. };
  12.  
  13. struct B {
  14. double x;
  15.  
  16. double b(double k) {
  17. std::cout << "b! " << x << ", " << k << "\n";
  18. return x - k;
  19. }
  20.  
  21. void b() {
  22. std::cout << "b! " << x << ", ?\n";
  23. }
  24. };
  25.  
  26. struct C {
  27. A *_first__;
  28. B *_second__;
  29. C(A * _first__, B * _second__):_first__(_first__), _second__(_second__) {
  30. } template < typename K, typename ... T > static auto _a_caller__(K * k, T && ... args)->decltype(k->a(std::forward < T > (args) ...)) {
  31. return k->a(std::forward < T > (args)...);
  32. }
  33. template < typename...T > auto a(T &&...args)->decltype(_a_caller__(_first__, std::forward < T > (args)...)) {
  34. return _a_caller__(_first__, std::forward < T > (args)...);
  35. }
  36. template < typename...T > auto a(T &&...args)->decltype(_a_caller__(_second__, std::forward < T > (args)...)) {
  37. return _a_caller__(_second__, std::forward < T > (args)...);
  38. }
  39. template < typename K, typename...T > static auto _b_caller__(K * k, T && ... args)->decltype(k->b(std::forward < T > (args) ...)) {
  40. return k->b(std::forward < T > (args)...);
  41. }
  42. template < typename...T > auto b(T &&...args)->decltype(_b_caller__(_first__, std::forward < T > (args)...)) {
  43. return _b_caller__(_first__, std::forward < T > (args)...);
  44. }
  45. template < typename...T > auto b(T &&...args)->decltype(_b_caller__(_second__, std::forward < T > (args)...)) {
  46. return _b_caller__(_second__, std::forward < T > (args)...);
  47. }
  48. };
  49.  
  50. int main() {
  51. A a {12};
  52. B b {24};
  53.  
  54. C c (&a, &b);
  55.  
  56. c.a();
  57. c.b();
  58. std::cout << c.b(2445) << std::endl;
  59. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'decltype (decltype (k->.a((forward<T>)(C::_a_caller__::args)...)) C::_a_caller__(((C*)0)->C::_first__, (forward<T>)(C::a::args)...)) C::a(T&& ...) [with T = {}, decltype (C::_a_caller__(((C*)0)->C::_first__, (forward<T>)(C::a::args)...)) = void]':
prog.cpp:56:9:   instantiated from here
prog.cpp:33:36: sorry, unimplemented: mangling overload
prog.cpp: In instantiation of 'decltype (decltype (k->.b((forward<T>)(C::_b_caller__::args)...)) C::_b_caller__(((C*)0)->C::_second__, (forward<T>)(C::b::args)...)) C::b(T&& ...) [with T = {}, decltype (C::_b_caller__(((C*)0)->C::_second__, (forward<T>)(C::b::args)...)) = void]':
prog.cpp:57:9:   instantiated from here
prog.cpp:45:36: sorry, unimplemented: mangling overload
prog.cpp: In instantiation of 'decltype (decltype (k->.b((forward<T>)(C::_b_caller__::args)...)) C::_b_caller__(((C*)0)->C::_second__, (forward<T>)(C::b::args)...)) C::b(T&& ...) [with T = {int}, decltype (C::_b_caller__(((C*)0)->C::_second__, (forward<T>)(C::b::args)...)) = double]':
prog.cpp:58:26:   instantiated from here
prog.cpp:45:36: sorry, unimplemented: mangling overload
stdout

Standard output is empty