OpenKalman
make_constant.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) 2022-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 
16 #ifndef OPENKALMAN_MAKE_CONSTANT_HPP
17 #define OPENKALMAN_MAKE_CONSTANT_HPP
18 
22 
23 namespace OpenKalman
24 {
31 #ifdef __cpp_concepts
32  template<values::value C, patterns::pattern_collection P> requires values::fixed<collections::size_of<P>>
33  constexpr constant_object auto
34 #else
35  template<typename C, typename P, std::enable_if_t<
36  values::value<C> and
37  patterns::pattern_collection<P> and
38  values::fixed<collections::size_of<P>>, int> = 0>
39  constexpr auto
40 #endif
41  make_constant(C c, P&& p)
42  {
43  decltype(auto) extents = patterns::to_extents(std::forward<P>(p));
46  auto m = stdex::mdspan {std::move(c), mapping, accessor};
47  return attach_patterns(std::move(m), std::forward<P>(p));
48  }
49 
50 
55 #ifdef __cpp_concepts
56  template<values::value C, patterns::pattern...Ps>
57  constexpr constant_object auto
58 #else
59  template<typename C, typename...Ps, std::enable_if_t<values::value<C> and (... and patterns::pattern<Ps>), int> = 0>
60  constexpr auto
61 #endif
62  make_constant(C c, Ps&&...ps)
63  {
64  return make_constant(std::move(c), std::tuple{std::forward<Ps>(ps)...});
65  }
66 
67 
72 #ifdef __cpp_concepts
73  template<patterns::pattern_collection P, values::value C> requires
74  std::default_initializable<P> and
75  values::fixed<collections::size_of<P>>
76  constexpr constant_object auto
77 #else
78  template<typename P, typename C, std::enable_if_t<
79  patterns::pattern_collection<P> and
80  values::value<C> and
81  values::fixed<collections::size_of<P>>, int> = 0>
82  constexpr auto
83 #endif
85  {
86  return make_constant(std::move(c), P{});
87  }
88 
89 
90 }
91 
92 #endif
Definition: constant_mdspan_policies.hpp:31
Definition for constant_object.
Definitions for attach_patterns.
decltype(auto) constexpr attach_patterns(Arg &&arg, P &&p)
Attach a pattern_collection to an indexible object.
Definition: attach_patterns.hpp:74
constexpr bool pattern
An object describing the characteristics (e.g., dimensions, wrapping structure) of an index...
Definition: pattern.hpp:31
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: mdspan.hpp:34
Definition: constant_mdspan_policies.hpp:96
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr auto make_constant(C c, P &&p)
Make an indexible object in which every element is a constant value.
Definition: make_constant.hpp:41
constexpr bool constant_object
Specifies that all elements of an object are known at compile time to be the same constant value...
Definition: constant_object.hpp:54
constexpr auto to_extents(P &&p)
Convert a pattern_collection to std::extents.
Definition: to_extents.hpp:78