fork download
  1. #include <cstdio>
  2.  
  3. class tag;
  4.  
  5. template<class>
  6. struct type { friend constexpr auto get(type); };
  7.  
  8. template<class TKey, class TValue>
  9. struct set { friend constexpr auto get(TKey) { return TValue{}; } };
  10.  
  11. struct pituh { auto operator ()(auto value) { std::printf("called %d", value); } };
  12.  
  13. void foo() { // never called
  14. if constexpr(false) { // never true
  15. if (false) { // never true
  16. constexpr auto call = pituh{};
  17. void(set<type<tag>, decltype(call)>{});
  18. }
  19. }
  20. }
  21.  
  22. int main() {
  23. get(type<tag>{})(42); // prints called 42
  24. }
  25.  
Success #stdin #stdout 0s 4580KB
stdin
Standard input is empty
stdout
called 42