fork(3) download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct A {};
  7. struct B {};
  8. struct C {};
  9. struct D {};
  10. struct E {};
  11.  
  12. template <typename H>
  13. auto foo (H h, enable_if_t<
  14. is_same<typename result_of<H(A)>::type, bool>::value>* = 0)
  15. {
  16. return [h] (B x) { return h (A {}); };
  17. }
  18.  
  19. template <typename H>
  20. auto foo (H h, enable_if_t<
  21. is_same<typename result_of<H(B)>::type, bool>::value>* = 0)
  22. {
  23. return [h] (C x) { return h (B {}); };
  24. }
  25.  
  26. template <typename H>
  27. auto foo (H h, enable_if_t<
  28. is_same<typename result_of<H(C)>::type, bool>::value>* = 0)
  29. {
  30. return [h] (D x) { return h (C {}); };
  31. }
  32.  
  33. template <typename H>
  34. auto foo (H h, enable_if_t<
  35. is_same<typename result_of<H(D)>::type, bool>::value>* = 0)
  36. {
  37. return [h] (E x) { return h (D {}); };
  38. }
  39.  
  40. #include <boost/utility/result_of.hpp>
  41. #include <boost/type_traits.hpp>
  42.  
  43. template <typename Stop, typename Handler, typename Result>
  44. struct call_until_helper
  45. {
  46. call_until_helper (Handler)
  47. {
  48. }
  49. };
  50.  
  51. template <typename Stop, typename Handler>
  52. call_until_helper<Stop, Handler,
  53. typename boost::function_traits<Handler>::result_type>
  54. call_until (Handler handler)
  55. {
  56. return call_until_helper<Stop, Handler,
  57. typename boost::function_traits<Handler>::result_type> (handler);
  58. }
  59.  
  60. int main ()
  61. {
  62. auto inner_handler = [] (A) -> bool { return false; };
  63.  
  64. // auto f = foo (foo (foo (foo ( inner_handler ))));
  65. auto f = call_until<E> ( inner_handler );
  66.  
  67. std::cout << f (E {}) << "\n";
  68. }
Compilation error #stdin compilation error #stdout 0s 3140KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/boost/type_traits.hpp:27:0,
                 from prog.cpp:41:
/usr/include/boost/type_traits/function_traits.hpp: In instantiation of 'struct boost::function_traits<main()::<lambda(A)> >':
prog.cpp:54:1:   required by substitution of 'template<class Stop, class Handler> call_until_helper<Stop, Handler, typename boost::function_traits<Handler>::result_type> call_until(Handler) [with Stop = E; Handler = main()::<lambda(A)>]'
prog.cpp:65:41:   required from here
/usr/include/boost/type_traits/function_traits.hpp:168:8: error: invalid use of incomplete type 'struct boost::detail::function_traits_helper<main()::<lambda(A)>*>'
 struct function_traits : 
        ^
/usr/include/boost/type_traits/function_traits.hpp:21:36: error: declaration of 'struct boost::detail::function_traits_helper<main()::<lambda(A)>*>'
 template<typename Function> struct function_traits_helper;
                                    ^
prog.cpp: In function 'int main()':
prog.cpp:65:41: error: no matching function for call to 'call_until(main()::<lambda(A)>&)'
  auto f = call_until<E> ( inner_handler );
                                         ^
prog.cpp:65:41: note: candidate is:
prog.cpp:54:1: note: template<class Stop, class Handler> call_until_helper<Stop, Handler, typename boost::function_traits<Handler>::result_type> call_until(Handler)
 call_until (Handler handler)
 ^
prog.cpp:54:1: note:   substitution of deduced template arguments resulted in errors seen above
stdout
Standard output is empty