libevdevxx 0.5.0
A C++ wrapper for libevdev.
Loading...
Searching...
No Matches
NumberBase.hpp
Go to the documentation of this file.
1/*
2 * libevdevxx - a C++ wrapper for libevdev
3 *
4 * Copyright (C) 2025 Daniel K. O.
5 * SPDX-License-Identifier: MIT
6 */
7
8#ifndef LIBEVDEVXX_NUMBER_BASE_HPP
9#define LIBEVDEVXX_NUMBER_BASE_HPP
10
11#include <compare>
12
13
14namespace evdev::detail {
15
16 // this template uses CRTP to create a type-safe integer
17
18
19 template<typename T,
20 typename D>
21 class NumberBase {
22
23 protected:
24
25 using Value = T;
26 using Derived = D;
27
29
30 public:
31
32 constexpr
33 NumberBase() noexcept :
34 value{0}
35 {}
36
37
38 constexpr
39 explicit
42 {}
43
44
45 constexpr
46 operator Value()
47 const noexcept
48 {
49 return value;
50 }
51
52
53 // comparators
54
55
56 constexpr
57 bool
58 operator ==(const NumberBase& other)
59 const noexcept = default;
60
61 constexpr
62 std::strong_ordering
63 operator <=>(const NumberBase& other)
64 const noexcept = default;
65
66
67 constexpr
69 operator ++() noexcept
70 {
71 ++value;
72 return *this;
73 }
74
75
76 constexpr
78 operator ++(int) noexcept
79 {
80 Derived old{*this};
81 ++value;
82 return old;
83 }
84
85 };
86
87} // namespace evdev::detail
88
89#endif
Code Derived
Definition NumberBase.hpp:26
constexpr NumberBase & operator++() noexcept
Definition NumberBase.hpp:69
constexpr NumberBase() noexcept
Definition NumberBase.hpp:33
Value value
Definition NumberBase.hpp:28
constexpr bool operator==(const NumberBase &other) const noexcept=default
constexpr std::strong_ordering operator<=>(const NumberBase &other) const noexcept=default
constexpr NumberBase(Value value) noexcept
Definition NumberBase.hpp:40
std::uint16_t Value
Definition NumberBase.hpp:25
Definition basic_wrapper.hpp:17