OpenKalman
constant_mdspan_policies.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) 2025-2026 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 
17 #ifndef OPENKALMAN_CONSTANT_MDSPAN_POLICIES_HPP
18 #define OPENKALMAN_CONSTANT_MDSPAN_POLICIES_HPP
19 
20 #include "basics/basics.hpp"
21 
22 namespace OpenKalman::interface
23 {
29  {
30  template<class Extents>
31  struct mapping
32  {
33  using extents_type = Extents;
34  using index_type = typename extents_type::index_type;
35  using size_type = typename extents_type::size_type;
36  using rank_type = typename extents_type::rank_type;
38 
39  constexpr explicit
40  mapping(const extents_type& e) : extents_(e) {}
41 
42  constexpr const extents_type&
43  extents() const noexcept { return extents_; }
44 
45 #ifdef __cpp_concepts
46  constexpr index_type
47  operator() (std::convertible_to<index_type> auto...i) const
48 #else
49  template<typename...IndexTypes, std::enable_if_t<
50  (... and std::is_convertible_v<IndexTypes, index_type>), int> = 0>
51  constexpr index_type
52  operator() (IndexTypes...i) const
53 #endif
54  {
55  return 0;
56  }
57 
58  constexpr index_type
59  required_span_size() const noexcept
60  {
61  for(unsigned r = 0; r < extents_type::rank(); r++) if (extents().extent(r) == 0) return 0;
62  return 1;
63  }
64 
65  static constexpr bool is_always_unique() noexcept { return false; }
66  static constexpr bool is_always_exhaustive() noexcept { return false; }
67  static constexpr bool is_always_strided() noexcept { return false; }
68 
69  constexpr bool is_unique() const { return false; }
70  constexpr bool is_exhaustive() const { return false; }
71  constexpr bool is_strided() const { return false; }
72 
73  constexpr index_type
74  stride(std::size_t) const { return 0; }
75 
76  template<class OtherExtents>
77  friend constexpr bool
78  operator==(const mapping& lhs, const mapping<OtherExtents>& rhs) noexcept
79  {
80  return lhs.extents() == rhs.extents();
81  }
82 
83  private:
84 
85  extents_type extents_;
86 
87  };
88  };
89 
90 
95  template<typename ElementType>
97  using element_type = ElementType;
98  using reference = const element_type;
99  using data_handle_type = element_type;
101 
102  constexpr constant_accessor() noexcept = default;
103 
104 #ifdef __cpp_concepts
105  template<stdex::convertible_to<element_type> OtherElementType> requires
106  (not std::is_same_v<element_type, OtherElementType>)
107 #else
108  template<typename OtherElementType, std::enable_if_t<
109  stdex::convertible_to<OtherElementType, element_type> and
110  (not std::is_same_v<element_type, OtherElementType>), int> = 0>
111 #endif
112  constexpr constant_accessor(const constant_accessor<OtherElementType>& other) noexcept {}
113 
114  constexpr reference
115  access(data_handle_type p, std::size_t) const noexcept { return std::move(p); }
116 
117  constexpr data_handle_type
118  offset(data_handle_type p, std::size_t) const noexcept { return std::move(p); }
119 
120  };
121 
122 
123 }
124 
125 #endif
Definition: constant_mdspan_policies.hpp:31
Definition: basics.hpp:41
Definition: constant_mdspan_policies.hpp:96
decltype(auto) constexpr access(Arg &&arg, const Indices &indices)
Access a component of an indexible object at a given set of indices.
Definition: access.hpp:74
Basic definitions for OpenKalman as a whole.
Definition: constant_mdspan_policies.hpp:28