VCTR
Loading...
Searching...
No Matches
Range.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2023 by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr
24{
25
30template <is::realNumber ValueType>
31class Range
32{
33public:
34 using value_type = ValueType;
35
36 //==============================================================================
41 constexpr Range (ValueType startValue, ValueType endValue) noexcept
42 : start (startValue),
43 end (endValue)
44 {
45 VCTR_ASSERT (end >= start);
46 }
47
49 constexpr Range() = default;
50
52 constexpr Range (const Range&) = default;
53
55 constexpr Range (Range&&) = default;
56
57 //==============================================================================
59 constexpr void setStart (ValueType newStart) noexcept
60 {
61 start = newStart;
62 VCTR_ASSERT (start <= end);
63 }
64
66 constexpr void setEnd (ValueType newEnd) noexcept
67 {
68 end = newEnd;
69 VCTR_ASSERT (start <= end);
70 }
71
72 //==============================================================================
74 constexpr ValueType getStart() const noexcept { return start; }
75
77 constexpr ValueType getLength() const noexcept { return end - start; }
78
80 constexpr ValueType getEnd() const noexcept { return end; }
81
82private:
83 //==============================================================================
84 ValueType start { 0 };
85 ValueType end { 0 };
86};
87
88}
A simple range class.
Definition: Range.h:32
constexpr Range()=default
Constructs an empty range.
constexpr ValueType getStart() const noexcept
Returns the start of the range.
Definition: Range.h:74
constexpr Range(Range &&)=default
Move constructor.
constexpr Range(const Range &)=default
Copy constructor.
constexpr void setStart(ValueType newStart) noexcept
Sets a new start value.
Definition: Range.h:59
constexpr ValueType getEnd() const noexcept
Returns the end of the range.
Definition: Range.h:80
constexpr void setEnd(ValueType newEnd) noexcept
Sets a new end value.
Definition: Range.h:66
constexpr ValueType getLength() const noexcept
Returns the length of the range.
Definition: Range.h:77
constexpr Range(ValueType startValue, ValueType endValue) noexcept
Constructs a range with given start and end values.
Definition: Range.h:41
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201