Mir
int_wrapper.h
Go to the documentation of this file.
1/*
2 * Copyright ©, 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
17#ifndef MIR_INT_WRAPPER_H_
18#define MIR_INT_WRAPPER_H_
19
20#include <iosfwd>
21
22namespace mir
23{
24template<typename Tag, typename ValueType=int>
26{
27public:
28 constexpr IntWrapper() : value(0) {}
29
30 explicit constexpr IntWrapper(ValueType value) : value(value) {}
31 ValueType constexpr as_value() const { return value; }
32
33private:
34 ValueType value;
35};
36
37template<typename Tag, typename ValueType>
38std::ostream& operator<<(std::ostream& out, IntWrapper<Tag,ValueType> const& value)
39{
40 out << value.as_value();
41 return out;
42}
43
44template<typename Tag, typename ValueType>
45inline constexpr bool operator == (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
46{
47 return lhs.as_value() == rhs.as_value();
48}
49
50template<typename Tag, typename ValueType>
51inline constexpr bool operator != (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
52{
53 return lhs.as_value() != rhs.as_value();
54}
55
56template<typename Tag, typename ValueType>
57inline constexpr bool operator <= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
58{
59 return lhs.as_value() <= rhs.as_value();
60}
61
62template<typename Tag, typename ValueType>
63inline constexpr bool operator >= (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
64{
65 return lhs.as_value() >= rhs.as_value();
66}
67
68template<typename Tag, typename ValueType>
69inline constexpr bool operator < (IntWrapper<Tag,ValueType> const& lhs, IntWrapper<Tag,ValueType> const& rhs)
70{
71 return lhs.as_value() < rhs.as_value();
72}
73}
74
75#include <functional>
76namespace std
77{
78template<typename Tag, typename ValueType>
79struct hash< ::mir::IntWrapper<Tag,ValueType> >
80{
81 std::hash<int> self;
82 constexpr std::size_t operator()(::mir::IntWrapper<Tag,ValueType> const& id) const
83 {
84 return self(id.as_value());
85 }
86};
87}
88
89#endif // MIR_INT_WRAPPER_H_
Definition: int_wrapper.h:26
constexpr IntWrapper(ValueType value)
Definition: int_wrapper.h:30
ValueType constexpr as_value() const
Definition: int_wrapper.h:31
constexpr IntWrapper()
Definition: int_wrapper.h:28
Definition: runner.h:27
constexpr bool operator<=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:57
constexpr bool operator!=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:51
constexpr bool operator>=(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:63
constexpr bool operator==(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:45
constexpr bool operator<(IntWrapper< Tag, ValueType > const &lhs, IntWrapper< Tag, ValueType > const &rhs)
Definition: int_wrapper.h:69
std::hash< int > self
Definition: int_wrapper.h:81
constexpr std::size_t operator()(::mir::IntWrapper< Tag, ValueType > const &id) const
Definition: int_wrapper.h:82

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.