fork(1) download
  1. #include <iostream>
  2.  
  3. struct Wibble
  4. {
  5. static const bool CAN_WIBBLE = true;
  6. };
  7.  
  8. struct Wobble
  9. {
  10. static const bool CAN_WIBBLE = false;
  11. };
  12.  
  13. struct Foo
  14. {
  15. template<bool wibble>
  16. void _doStuff();
  17.  
  18. public:
  19. template<typename T>
  20. void doStuff()
  21. {
  22. _doStuff<T::CAN_WIBBLE>();
  23. }
  24. };
  25.  
  26. template<>
  27. void Foo::_doStuff<true>() { std::cout << "wibble ..." << std::endl; }
  28.  
  29. template<>
  30. void Foo::_doStuff<false>() { std::cout << "I can't wibble ..." << std::endl; }
  31.  
  32. int main()
  33. {
  34. Foo f;
  35. f.doStuff<Wibble>();
  36. f.doStuff<Wobble>();
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
wibble ...
I can't wibble ...