SHARE
TWEET

template

a guest Feb 28th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. template <typename T>
  4. struct Bad {
  5.     friend std::ostream& operator <<(std::ostream& os, const Bad<T>& a);
  6. };
  7.  
  8. template <typename T>
  9. std::ostream& operator <<(std::ostream& os, const Bad<T>& bad) {
  10.     (void)bad;
  11.     return os << "i'm bad";
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. template <typename T>
  19. struct Ok {
  20.     template <typename X>
  21.     friend std::ostream& operator <<(std::ostream& os, const Ok<X>& a);
  22. };
  23.  
  24.  
  25.  
  26.  
  27.  
  28. template <typename T>
  29. std::ostream& operator <<(std::ostream& os, const Ok<T>& ok) {
  30.     (void)ok;
  31.     return os << "i'm ok";
  32. }
  33.  
  34. int main() {
  35.     std::cout << Ok<int>() << std::endl;
  36.     //std::cout << Bad<int>() << std::endl;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top