exchange
Low-latency exchange in C++
Loading...
Searching...
No Matches
quantity.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <compare>
5#include <limits>
6namespace exchange::server
7{
8struct Quantity
9{
10 uint64_t value{};
11 constexpr Quantity() = default;
12 constexpr explicit Quantity(const uint64_t value) : value(value)
13 {
14 }
15
16 auto operator<=>(const Quantity &other) const = default;
17
18 constexpr auto operator-(const Quantity &other) const
19 {
20 return Quantity(value - other.value);
21 }
22 constexpr void operator+=(const Quantity &other)
23 {
24 value += other.value;
25 }
26 constexpr void operator-=(const Quantity &other)
27 {
28 value -= other.value;
29 }
30};
31} // namespace exchange::server
32
33template <> class std::numeric_limits<exchange::server::Quantity> : public std::numeric_limits<uint64_t>
34{
35 public:
36 static constexpr bool is_specialized = true;
37
38 static constexpr exchange::server::Quantity max() noexcept
39 {
40 return exchange::server::Quantity{std::numeric_limits<uint64_t>::max()};
41 }
42
43 static constexpr exchange::server::Quantity min() noexcept
44 {
45 return exchange::server::Quantity{std::numeric_limits<uint64_t>::min()};
46 }
47};
static constexpr bool is_specialized
Definition quantity.hpp:36
static constexpr exchange::server::Quantity min() noexcept
Definition quantity.hpp:43
static constexpr exchange::server::Quantity max() noexcept
Definition quantity.hpp:38
Definition main.hpp:4
Definition cli_parsing.hpp:10
Definition quantity.hpp:9
auto operator<=>(const Quantity &other) const =default
constexpr void operator+=(const Quantity &other)
Definition quantity.hpp:22
constexpr void operator-=(const Quantity &other)
Definition quantity.hpp:26
constexpr Quantity(const uint64_t value)
Definition quantity.hpp:12
uint64_t value
Definition quantity.hpp:10
constexpr auto operator-(const Quantity &other) const
Definition quantity.hpp:18
constexpr Quantity()=default