Advertisement
bueddl

Untitled

Jun 19th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class debug
  4. {
  5. private:
  6.     class base_var
  7.     {
  8.     };
  9.  
  10. public:
  11.     template<typename T>
  12.     class var : public base_var
  13.     {
  14.     public:
  15.         var(const T& value)
  16.             : m_value(value)
  17.         {
  18.         }
  19.        
  20.         inline var& operator=(const T& value)
  21.         {
  22.             if ((m_value = value) > m_th)
  23.                 std::cerr << "var raised above treshold (" << m_value << " > " << m_th << ")" << std::endl;
  24.         }
  25.  
  26.         operator T() const
  27.         {
  28.             return m_value;
  29.         }
  30.  
  31.         void notify_above(T treshold)
  32.         {
  33.             m_th = treshold;
  34.         }
  35.  
  36.     private:
  37.         T m_value;
  38.  
  39.         T m_th;
  40.     };
  41. };
  42.  
  43. int main(void)
  44. {
  45.     debug::var<int> i = 0;
  46.     i.notify_above(1000);
  47.  
  48.     for (int k = 0; k <= 1000; ++k)
  49.         i = k;
  50.  
  51.     i = 1337;
  52.  
  53.     int unwatched_var = i;
  54.     std::cout << "var = " << unwatched_var << std::endl;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement