Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. template<typename T> class wrapper
  2. {
  3. T*const ptr;
  4. wrapper(T*p) : ptr(p) {}
  5. public:
  6. bool empty() const { return ptr; }
  7. operator T& () const
  8. {
  9. if(empty()) throw some_exception("trying to use empty wrapper");
  10. return *ptr;
  11. }
  12. friend some_class;
  13. };
  14.  
  15. class some_class
  16. {
  17. ifstream _ifstream;
  18. ofstream _ofstream;
  19. bool ifstream_is_active;
  20. bool ofstream_is_active;
  21. public:
  22. operator wrapper<ifstream> () const
  23. { wrapper<ifstream>(ifstream_is_active? &_ifstream : 0); }
  24. operator wrapper<ofstream> () const
  25. { wrapper<ofstream>(ofstream_is_active? &_ofstream : 0); }
  26. };
Add Comment
Please, Sign In to add comment