pairinteraction
A Rydberg Interaction Calculator
Range.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
7
8namespace pairinteraction {
9template <typename Sortable>
10class Range {
12
13public:
14 Range() = default;
15 Range(Sortable min, Sortable max) : _min(min), _max(max), _is_finite(true) {
16 if (max < min) {
17 throw std::invalid_argument("It must be max >= min.");
18 }
19 }
20 Sortable min() const {
21 if (!_is_finite) {
22 throw std::runtime_error("The range is infinite.");
23 }
24 return _min;
25 }
26 Sortable max() const {
27 if (!_is_finite) {
28 throw std::runtime_error("The range is infinite.");
29 }
30 return _max;
31 }
32 bool is_finite() const { return _is_finite; }
33
34private:
35 Sortable _min{};
36 Sortable _max{};
37 bool _is_finite{false};
38};
39} // namespace pairinteraction
bool is_finite() const
Definition: Range.hpp:32
Range(Sortable min, Sortable max)
Definition: Range.hpp:15
Sortable min() const
Definition: Range.hpp:20
Sortable max() const
Definition: Range.hpp:26
Helper struct to extract whether a type supports certain operations.
Definition: traits.hpp:63