LocARNA-1.8.11
type_wrapper.hh
1 #ifndef LOCARNA_TYPE_WRAPPER_HH
2 #define LOCARNA_TYPE_WRAPPER_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 namespace LocARNA {
15  template<class T>
16  class type_wrapper {
17  T val_;
18  public:
19 
23  type_wrapper(): val_() {}
24 
28  explicit type_wrapper(const T &i): val_(i) {}
29 
33  type_wrapper(const type_wrapper &idx): val_(idx.val()) {}
34 
43  const T &val() const {return val_;}
44 
50  bool operator ==(const type_wrapper &x) const {return val_ == x.val_;}
51 
52 
58  bool operator !=(const type_wrapper &x) const {return val_ != x.val_;}
59 
65  bool operator <=(const type_wrapper &x) const {return val_ <= x.val_;}
66 
72  bool operator <(const type_wrapper &x) const {return val_ < x.val_;}
73 
79  bool operator >=(const type_wrapper &x) const {return val_ >= x.val_;}
80 
86  bool operator >(const type_wrapper &x) const {return val_ > x.val_;}
87 
93  type_wrapper operator +(const type_wrapper &x) const {return type_wrapper(val_ + x.val_);}
94 
100  type_wrapper operator -(const type_wrapper &x) const {return type_wrapper(val_ - x.val_);}
101 
107  type_wrapper operator +(const T &x) const {return type_wrapper(val_ + x);}
108 
114  type_wrapper operator -(const T &x) const {return type_wrapper(val_ - x);}
115 
120  const type_wrapper &operator ++() {++val_; return *this;}
121 
126  const type_wrapper &operator --() {--val_; return *this;}
127 
132  const type_wrapper &operator ++(int) {type_wrapper<T> tmp(*this); ++val_; return tmp;}
133 
138  const type_wrapper &operator --(int) {type_wrapper<T> tmp(*this); --val_; return tmp;}
139 
140  }; // end class type_wrapper
141 
142  template <class T>
143  std::ostream & operator << (std::ostream &out,const type_wrapper<T> &x) {
144  out<<x.val();
145  return out;
146  }
147 
148 } // end namespace LocARNA
149 
150 #endif // LOCARNA_TYPE_WRAPPER_HH
bool operator<(const type_wrapper &x) const
less
Definition: type_wrapper.hh:72
bool operator!=(const type_wrapper &x) const
inequal
Definition: type_wrapper.hh:58
type_wrapper(const type_wrapper &idx)
copy constructor
Definition: type_wrapper.hh:33
const T & val() const
casting to T
Definition: type_wrapper.hh:43
Definition: aligner.cc:17
const type_wrapper & operator++()
prefix increment
Definition: type_wrapper.hh:120
bool operator>(const type_wrapper &x) const
greater
Definition: type_wrapper.hh:86
generic type_wrapper class
Definition: type_wrapper.hh:16
bool operator<=(const type_wrapper &x) const
less equal
Definition: type_wrapper.hh:65
bool operator==(const type_wrapper &x) const
equal
Definition: type_wrapper.hh:50
type_wrapper operator+(const type_wrapper &x) const
add
Definition: type_wrapper.hh:93
bool operator>=(const type_wrapper &x) const
greater equal
Definition: type_wrapper.hh:79
type_wrapper operator-(const type_wrapper &x) const
subtract
Definition: type_wrapper.hh:100
const type_wrapper & operator--()
prefix decrement
Definition: type_wrapper.hh:126
type_wrapper()
default constructor
Definition: type_wrapper.hh:23
type_wrapper(const T &i)
conversion constructor
Definition: type_wrapper.hh:28