Mir
int_wrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored By: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_INT_WRAPPER_H_
20 #define MIR_INT_WRAPPER_H_
21 
22 #include <iosfwd>
23 
24 namespace mir
25 {
26 template<typename Tag, typename ValueType=int>
28 {
29 public:
30  IntWrapper() : value(0) {}
31 
32  explicit IntWrapper(ValueType value) : value(value) {}
33  ValueType as_value() const { return value; }
34 
35 private:
36  ValueType value;
37 };
38 
39 template<typename Tag, typename ValueType>
40 std::ostream& operator<<(std::ostream& out, IntWrapper<Tag,ValueType> const& value)
41 {
42  out << value.as_value();
43  return out;
44 }
45 
46 template<typename Tag, typename ValueType>
48 {
49  return lhs.as_value() == rhs.as_value();
50 }
51 
52 template<typename Tag, typename ValueType>
54 {
55  return lhs.as_value() != rhs.as_value();
56 }
57 
58 template<typename Tag, typename ValueType>
59 inline bool operator <= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
60 {
61  return lhs.as_value() <= rhs.as_value();
62 }
63 
64 template<typename Tag, typename ValueType>
66 {
67  return lhs.as_value() >= rhs.as_value();
68 }
69 
70 template<typename Tag, typename ValueType>
71 inline bool operator < (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
72 {
73  return lhs.as_value() < rhs.as_value();
74 }
75 }
76 
77 #include <functional>
78 namespace std
79 {
80 template<typename Tag, typename ValueType>
81 struct hash< ::mir::IntWrapper<Tag,ValueType> >
82 {
83  std::hash<int> self;
84  std::size_t operator()(::mir::IntWrapper<Tag,ValueType> const& id) const
85  {
86  return self(id.as_value());
87  }
88 };
89 }
90 
91 #endif // MIR_INT_WRAPPER_H_
All things Mir.
Definition: buffer_stream.h:37
bool operator==(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:47
STL namespace.
ValueType as_value() const
Definition: int_wrapper.h:33
IntWrapper()
Definition: int_wrapper.h:30
bool operator>=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:65
IntWrapper(ValueType value)
Definition: int_wrapper.h:32
bool operator!=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:53
Definition: int_wrapper.h:27
std::size_t operator()(::mir::IntWrapper< Tag, ValueType > const &id) const
Definition: int_wrapper.h:84

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015