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
24namespace mir
25{
26template<typename Tag, typename ValueType=int>
28{
29public:
30 constexpr IntWrapper() : value(0) {}
31
32 explicit constexpr IntWrapper(ValueType value) : value(value) {}
33 ValueType constexpr as_value() const { return value; }
34
35private:
36 ValueType value;
37};
38
39template<typename Tag, typename ValueType>
40std::ostream& operator<<(std::ostream& out, IntWrapper<Tag,ValueType> const& value)
41{
42 out << value.as_value();
43 return out;
44}
45
46template<typename Tag, typename ValueType>
47inline constexpr bool operator == (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
48{
49 return lhs.as_value() == rhs.as_value();
50}
51
52template<typename Tag, typename ValueType>
53inline constexpr bool operator != (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
54{
55 return lhs.as_value() != rhs.as_value();
56}
57
58template<typename Tag, typename ValueType>
59inline constexpr bool operator <= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
60{
61 return lhs.as_value() <= rhs.as_value();
62}
63
64template<typename Tag, typename ValueType>
65inline constexpr bool operator >= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
66{
67 return lhs.as_value() >= rhs.as_value();
68}
69
70template<typename Tag, typename ValueType>
71inline 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>
78namespace std
79{
80template<typename Tag, typename ValueType>
81struct 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_
Definition: int_wrapper.h:28
constexpr IntWrapper(ValueType value)
Definition: int_wrapper.h:32
ValueType constexpr as_value() const
Definition: int_wrapper.h:33
constexpr IntWrapper()
Definition: int_wrapper.h:30
Definition: splash_session.h:24
constexpr bool operator<=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:59
constexpr bool operator!=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:53
constexpr bool operator>=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:65
std::ostream & operator<<(std::ostream &out, IntWrapper< Tag, ValueType > const &value)
Definition: int_wrapper.h:40
constexpr bool operator==(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:47
constexpr bool operator<(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:71
STL namespace.
std::hash< int > self
Definition: int_wrapper.h:83
constexpr std::size_t operator()(::mir::IntWrapper< Tag, ValueType > const &id) const
Definition: int_wrapper.h:84

Copyright © 2012-2022 Canonical Ltd.
Generated on Sun Oct 9 06:13:38 UTC 2022
This documentation is licensed under the GPL version 2 or 3.