OpenKalman
VectorSpaceDescriptorRange.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2024 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_VECTORSPACEDESCRIPTORRANGE_HPP
17 #define OPENKALMAN_VECTORSPACEDESCRIPTORRANGE_HPP
18 
19 #include <cstddef>
20 #include <type_traits>
22 
23 namespace OpenKalman::internal
24 {
25  template<typename Indexible>
27  {
28  struct Iterator
29  {
30  using difference_type = std::ptrdiff_t;
31  using value_type = std::decay_t<decltype(get_vector_space_descriptor<0>(std::declval<Indexible>()))>;
32  static_assert(dynamic_pattern<value_type>);
33  constexpr Iterator(const Indexible& indexible, const std::size_t p) : my_indexible{indexible}, pos{p} {}
34  constexpr value_type operator*() const { return get_vector_space_descriptor(my_indexible, pos); }
35  constexpr auto& operator++() noexcept { ++pos; return *this; }
36  constexpr auto operator++(int) noexcept { auto temp = *this; ++*this; return temp; }
37  constexpr auto& operator--() noexcept { --pos; return *this; }
38  constexpr auto operator--(int) noexcept { auto temp = *this; --*this; return temp; }
39  constexpr auto& operator+=(const difference_type diff) noexcept { pos += diff; return *this; }
40  constexpr auto& operator-=(const difference_type diff) noexcept { pos -= diff; return *this; }
41  constexpr auto operator+(const difference_type diff) const noexcept { return Iterator {pos + diff}; }
42  constexpr auto operator-(const difference_type diff) const noexcept { return Iterator {pos - diff}; }
43  constexpr auto operator+(const Iterator& other) const noexcept { return Iterator {pos + other.pos}; }
44  constexpr difference_type operator-(const Iterator& other) const noexcept { return pos - other.pos; }
45  constexpr value_type operator[](difference_type offset) const { return get_vector_space_descriptor(my_indexible, pos + offset); }
46  constexpr bool operator==(const Iterator& other) const noexcept { return pos == other.pos; }
47 #ifdef __cpp_impl_three_way_comparison
48  constexpr auto operator<=>(const Iterator& other) const noexcept { return pos <=> other.pos; }
49 #else
50  constexpr bool operator!=(const Iterator& other) const noexcept { return pos != other.pos; }
51  constexpr bool operator<(const Iterator& other) const noexcept { return pos < other.pos; }
52  constexpr bool operator>(const Iterator& other) const noexcept { return pos > other.pos; }
53  constexpr bool operator<=(const Iterator& other) const noexcept { return pos <= other.pos; }
54  constexpr bool operator>=(const Iterator& other) const noexcept { return pos >= other.pos; }
55 #endif
56 
57  private:
58 
59  const Indexible& my_indexible;
60 
61  std::size_t pos;
62 
63  }; // struct Iterator
64 
65  constexpr VectorSpaceDescriptorRange(const VectorSpaceDescriptorRange& other) : my_indexible {other.my_indexible} {}
66 
67  constexpr VectorSpaceDescriptorRange(VectorSpaceDescriptorRange&& other) : my_indexible {other.my_indexible} {}
68 
69  constexpr VectorSpaceDescriptorRange(const Indexible& indexible) : my_indexible {indexible} {}
70 
71  constexpr auto begin() const { return Iterator {my_indexible, 0}; }
72 
73  constexpr auto end() const { return Iterator {my_indexible, count_indices(my_indexible)}; }
74 
75  constexpr std::size_t size() const { return count_indices(my_indexible); }
76 
77  private:
78 
79  const Indexible& my_indexible;
80 
81  };
82 
83 } // namespace OpenKalman::internal
84 
85 #endif //OPENKALMAN_VECTORSPACEDESCRIPTORRANGE_HPP
constexpr auto count_indices(const T &t)
Get the number of indices available to address the components of an indexible object.
Definition: count_indices.hpp:33
Definition: VectorSpaceDescriptorRange.hpp:28
Definition for coordinates::dynamic_pattern.
constexpr bool indexible
T is a generalized tensor type.
Definition: indexible.hpp:32
Definition: basics.hpp:48
constexpr auto get_vector_space_descriptor(const T &t, const N &n)
Get the coordinates::pattern object for index N of indexible object T.
Definition: get_vector_space_descriptor.hpp:56
Definition: VectorSpaceDescriptorRange.hpp:26