OpenKalman
array-object.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 
16 #ifndef OPENKALMAN_INTERFACES_ARRAYS_OBJECT_TRAITS_HPP
17 #define OPENKALMAN_INTERFACES_ARRAYS_OBJECT_TRAITS_HPP
18 
19 #include "basics/basics.hpp"
21 
22 namespace OpenKalman::interface
23 {
28 #ifdef __cpp_concepts
29  template<typename T> requires std::is_bounded_array_v<T>
30  struct object_traits<T>
31 #else
32  template<typename T>
33  struct object_traits<T, std::enable_if_t<stdex::is_bounded_array_v<T>>>
34 #endif
35  {
36  static const bool is_specialized = true;
37 
38  private:
39 
40  template<std::size_t rank = 0, std::size_t...es>
41  struct mdspan_extents : mdspan_extents<rank + 1, es..., std::extent_v<T, rank>> {};
42 
43  template<std::size_t...es>
44  struct mdspan_extents<std::rank_v<T>, es...> { using type = stdex::extents<std::size_t, es...>; };
45 
46  template<typename P>
47  static constexpr auto*
48  ptr_first_element(P* p)
49  {
50  if constexpr (std::rank_v<P> > 0)
51  return ptr_first_element(p[0]);
52  else
53  return p;
54  }
55 
56  public:
57 
61  static constexpr auto
62  get_mdspan = [](auto&& t)
63  {
64  using scalar = std::remove_all_extents_t<std::remove_reference_t<decltype(t)>>;
65  using ext = typename mdspan_extents<>::type;
66  return stdex::mdspan<scalar, ext>{ptr_first_element(t)};
67  };
68 
69  };
70 
71 }
72 
73 
74 #endif
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
Definition: basics.hpp:41
static const bool is_specialized
Identifies types for which object_traits is specialized.
Definition: object_traits.hpp:44
Definition: mdspan.hpp:34
Forward declaration of object_traits, which must be defined for all objects used in OpenKalman...
Definition: object_traits.hpp:38
Basic definitions for OpenKalman as a whole.
Definition: extents.hpp:372