blob: cfda5adc7e8a3dfde959b19a22ac6c0c2e38cc6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef INTWRAPPER_H
#define INTWRAPPER_H
#include "libsamplemacros.h"
// Wrapper around int for testing operators
class LIBSAMPLE_API IntWrapper
{
public:
constexpr explicit IntWrapper(int i) noexcept : m_number(i) {}
int toInt() const;
IntWrapper &operator++();
IntWrapper operator++(int); // Postfix
IntWrapper &operator--();
IntWrapper operator--(int); // Postfix
friend constexpr inline bool operator==(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number == rhs.m_number; }
friend constexpr inline bool operator!=(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number != rhs.m_number; }
friend constexpr inline bool operator<(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number < rhs.m_number; }
friend constexpr inline bool operator>(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number > rhs.m_number; }
friend constexpr inline bool operator<=(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number <= rhs.m_number; }
friend constexpr inline bool operator>=(IntWrapper lhs, IntWrapper rhs) noexcept
{ return lhs.m_number >= rhs.m_number; }
constexpr inline IntWrapper &operator+=(IntWrapper i);
constexpr inline IntWrapper &operator-=(const IntWrapper i);
friend constexpr inline IntWrapper operator+(IntWrapper lhs, IntWrapper rhs) noexcept
{ return IntWrapper(lhs.m_number + rhs.m_number); }
friend constexpr inline IntWrapper operator-(IntWrapper lhs, IntWrapper rhs) noexcept
{ return IntWrapper(lhs.m_number - rhs.m_number); }
// FIXME: Test spaceship operator with C++ 20:
// auto operator<=>(IntWrapper) const = default;
private:
int m_number;
};
constexpr inline IntWrapper &IntWrapper::operator+=(IntWrapper i)
{
m_number += i.m_number;
return *this;
}
constexpr inline IntWrapper &IntWrapper::operator-=(const IntWrapper i)
{
m_number -= i.m_number;
return *this;
}
#endif // INTWRAPPER_H
|