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 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::internal
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  constexpr index_type
46 #ifdef __cpp_concepts
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  operator() (IndexTypes...i) const
52 #endif
53  {
54  return 0;
55  }
56 
57  constexpr index_type
58  required_span_size() const noexcept { return 0; }
59 
60  static constexpr bool is_always_unique() noexcept { return false; }
61  static constexpr bool is_always_exhaustive() noexcept { return false; }
62  static constexpr bool is_always_strided() noexcept { return false; }
63 
64  constexpr bool is_unique() const { return false; }
65  constexpr bool is_exhaustive() const { return false; }
66  constexpr bool is_strided() const { return false; }
67 
68  constexpr index_type
69  stride(std::size_t) const { return 0; }
70 
71  template<class OtherExtents>
72  friend constexpr bool
73  operator==(const mapping& lhs, const mapping<OtherExtents>& rhs) noexcept
74  {
75  return lhs.extents() == rhs.extents();
76  }
77 
78  private:
79 
80  extents_type extents_;
81 
82  };
83  };
84 
85 
90  template<typename ElementType>
93  using element_type = ElementType;
94  using reference = const element_type&;
95  using data_handle_type = const element_type*;
96 
97  constexpr accessor_constant() noexcept = default;
98 
99 #ifdef __cpp_concepts
100  template<stdex::convertible_to<element_type> OtherElementType>
101 #else
102  template<typename OtherElementType, std::enable_if_t<stdex::convertible_to<OtherElementType, element_type>, int> = 0>
103 #endif
104  constexpr accessor_constant(const accessor_constant<OtherElementType>& other) noexcept
105  : element_ {other.element_} {}
106 
107 #ifdef __cpp_concepts
108  template<stdex::convertible_to<element_type> OtherElementType>
109 #else
110  template<typename OtherElementType, std::enable_if_t<stdex::convertible_to<OtherElementType, element_type>, int> = 0>
111 #endif
112  constexpr accessor_constant(accessor_constant<OtherElementType>&& other) noexcept
113  : element_ {std::move(other).element_} {}
114 
115  constexpr accessor_constant(ElementType e) : element_ {std::move(e)} {}
116 
117  constexpr reference
118  access(data_handle_type p, std::size_t i) const noexcept { return element_; }
119 
120  constexpr data_handle_type
121  offset(data_handle_type p, std::size_t i) const noexcept { return &element_; }
122 
123  constexpr data_handle_type
124  data_handle() const noexcept { return &element_; }
125 
126  private:
127 
128  const ElementType element_;
129 
130  template<typename OtherElementType>
131  friend struct accessor_constant;
132 
133  };
134 
135 
136 }
137 
138 #endif
Definition: constant_mdspan_policies.hpp:31
Definition: constant_mdspan_policies.hpp:28
Definition: constant_mdspan_policies.hpp:91
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: basics.hpp:48