Sequoia
Loading...
Searching...
No Matches
LinearSequence.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2020. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14namespace sequoia::maths
15{
16 template<class T, std::integral Index>
18 {
19 public:
20 using value_type = T;
21 using size_type = Index;
22
23 constexpr linear_sequence(T start, T step)
24 : m_Start{std::move(start)}
25 , m_Step{std::move(step)}
26 {}
27
28 [[nodiscard]]
29 constexpr T operator[](const size_type i) const { return m_Start + i * m_Step; }
30
31 [[nodiscard]]
32 constexpr T start() const noexcept { return m_Start; }
33
34 [[nodiscard]]
35 constexpr T step() const noexcept { return m_Step; }
36
37 [[nodiscard]]
38 friend constexpr bool operator==(const linear_sequence&, const linear_sequence&) noexcept = default;
39
40 [[nodiscard]]
41 friend constexpr bool operator!=(const linear_sequence&, const linear_sequence&) noexcept = default;
42 private:
43 T m_Start, m_Step;
44 };
45
46
47 template<class T, T Start, T Step, std::size_t Size, std::integral Index>
49 {
50 using value_type = T;
51 using size_type = Index;
52
53 [[nodiscard]]
54 constexpr T start() const noexcept { return Start; }
55
56 [[nodiscard]]
57 constexpr T step() const noexcept { return Step; }
58
59 [[nodiscard]]
60 constexpr std::size_t size() const noexcept { return Size; }
61
62 [[nodiscard]]
63 constexpr T operator[](const size_type i) const { return Start + i * Step; }
64
65 [[nodiscard]]
66 friend constexpr bool operator==(const static_linear_sequence&, const static_linear_sequence&) noexcept = default;
67 };
68}
Definition: LinearSequence.hpp:18
Definition: LinearSequence.hpp:49