fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <class F, class G>
  5. auto static_if (std::true_type, F && f, G && g) {
  6. return std::forward<F> (f) (0);
  7. }
  8.  
  9. template <class F, class G>
  10. auto static_if (std::false_type, F && f, G && g) {
  11. return std::forward<G> (g) (0);
  12. }
  13.  
  14.  
  15. template <class T> std::true_type constexpr is_pointer (T *) { return {}; }
  16. template <class T> std::false_type constexpr is_pointer (T) { return {}; }
  17.  
  18. int main() {
  19. int x = 5;
  20. static_if (
  21. is_pointer (x),
  22. [&] (auto) { auto y = x; std::cout << *y << std::endl; },
  23. [&] (auto) { std::cout << "no pointer" << std::endl; }
  24. );
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 3460KB
stdin
Standard input is empty
compilation info
prog.cpp: In lambda function:
prog.cpp:22:45: error: invalid type argument of unary '*' (have 'int')
      [&] (auto) { auto y = x; std::cout << *y << std::endl; },
                                             ^
stdout
Standard output is empty