Mir
include
core
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
>
27
class
IntWrapper
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