Mir
int_wrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2013, 2016 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 2 or 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  constexpr IntWrapper() : value(0) {}
31 
32  explicit constexpr IntWrapper(ValueType value) : value(value) {}
33  ValueType constexpr 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>
47 inline constexpr bool operator == (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
48 {
49  return lhs.as_value() == rhs.as_value();
50 }
51 
52 template<typename Tag, typename ValueType>
53 inline constexpr bool operator != (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
54 {
55  return lhs.as_value() != rhs.as_value();
56 }
57 
58 template<typename Tag, typename ValueType>
59 inline constexpr 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>
65 inline constexpr bool operator >= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
66 {
67  return lhs.as_value() >= rhs.as_value();
68 }
69 
70 template<typename Tag, typename ValueType>
71 inline constexpr 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  constexpr 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_
mir::operator>=
constexpr bool operator>=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:65
mir::IntWrapper::IntWrapper
constexpr IntWrapper()
Definition: int_wrapper.h:30
mir::IntWrapper::IntWrapper
constexpr IntWrapper(ValueType value)
Definition: int_wrapper.h:32
mir::operator<=
constexpr bool operator<=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:59
mir
Definition: splash_session.h:24
mir::operator<
constexpr bool operator<(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:71
mir::operator==
constexpr bool operator==(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:47
std::hash< ::mir::IntWrapper< Tag, ValueType > >::operator()
constexpr std::size_t operator()(::mir::IntWrapper< Tag, ValueType > const &id) const
Definition: int_wrapper.h:84
mir::operator!=
constexpr bool operator!=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:53
mir::IntWrapper::as_value
constexpr ValueType as_value() const
Definition: int_wrapper.h:33
mir::IntWrapper
Definition: int_wrapper.h:28
mir::operator<<
std::ostream & operator<<(std::ostream &out, IntWrapper< Tag, ValueType > const &value)
Definition: int_wrapper.h:40

Copyright © 2012-2020 Canonical Ltd.
Generated on Sun Sep 27 19:03:53 UTC 2020
This documentation is licensed under the GPL version 2 or 3.