fork download
  1. #include <iostream>
  2.  
  3. template<int n>
  4. struct bob
  5. {
  6. bob() {
  7. std::cout << "bob" << n << " reporting in\n";
  8. };
  9. };
  10.  
  11. struct bar {
  12. template<int n>
  13. void Do() const {
  14. bob<n> b;
  15. };
  16. };
  17.  
  18. template<int n=0,int bit=9>
  19. struct foo
  20. {
  21. template<typename F>
  22. void Do(unsigned int x,F&& f) {
  23. if ((x>>bit)&1) {
  24. foo<(n<<1)|1,bit-1>().Do(x,f);
  25. }
  26. else {
  27. foo<(n<<1),bit-1>().Do(x,f);
  28. };
  29. };
  30. };
  31.  
  32. template<int n>
  33. struct foo<n,-1>
  34. {
  35. template<typename F>
  36. void Do(unsigned int x,F&& f) const {
  37. f.template Do<n>();
  38. };
  39. };
  40.  
  41. template<typename F>
  42. void mojo(int x, F&& f)
  43. {
  44. foo<>()(x,f);
  45. }
  46.  
  47. int main()
  48. {
  49. mojo(7,bar());
  50. }
  51.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void mojo(int, F&&) [with F = bar]':
prog.cpp:49:17:   instantiated from here
prog.cpp:44:5: error: no match for call to '(foo<>) (int&, bar&)'
stdout
Standard output is empty