OpenKalman
replicate.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_COORDINATES_VIEWS_REPLICATE_HPP
17 #define OPENKALMAN_COORDINATES_VIEWS_REPLICATE_HPP
18 
20 
22 {
23  namespace detail
24  {
25  template<typename Factor>
26  struct replicate_closure : stdex::ranges::range_adaptor_closure<replicate_closure<Factor>>
27  {
28  constexpr replicate_closure(Factor f) : factor_ {std::move(f)} {};
29 
30 #ifdef __cpp_concepts
31  template<pattern R>
32 #else
33  template<typename R, std::enable_if_t<pattern<R>, int> = 0>
34 #endif
35  constexpr auto
36  operator() (R&& r) const
37  {
38  if constexpr (descriptor<R>)
39  return collections::views::repeat(std::forward<R>(r), factor_);
40  else
41  return collections::views::replicate(std::forward<R>(r), factor_);
42  }
43 
44  private:
45  Factor factor_;
46  };
47 
48 
50  {
51 #ifdef __cpp_concepts
52  template<values::index Factor>
53 #else
54  template<typename Factor, std::enable_if_t<values::index<Factor>, int> = 0>
55 #endif
56  constexpr auto
57  operator() (Factor factor) const
58  {
59  return replicate_closure<Factor> {std::move(factor)};
60  }
61 
62 
63 #ifdef __cpp_concepts
64  template<pattern R, values::index Factor>
65 #else
66  template<typename R, typename Factor, std::enable_if_t<pattern<R> and values::index<Factor>, int> = 0>
67 #endif
68  constexpr auto
69  operator() (R&& r, Factor factor) const
70  {
71  if constexpr (descriptor<R>)
72  return collections::views::repeat(std::forward<R>(r), std::move(factor));
73  else
74  return collections::views::replicate(std::forward<R>(r), std::move(factor));
75  }
76 
77  };
78 
79  }
80 
81 
87 
88 }
89 
90 
91 #endif
constexpr detail::replicate_adaptor replicate
a std::ranges::range_adaptor_closure for a set of replicated pattern objects.
Definition: replicate.hpp:86
constexpr detail::repeat_adaptor repeat
a std::ranges::range_adaptor_closure for a set of repeated collection objects.
Definition: repeat.hpp:148
constexpr detail::replicate_adaptor replicate
a std::ranges::range_adaptor_closure associated with replicate_view.
Definition: replicate.hpp:440
Inclusion file for collections.
The namespace for views for coordinates::pattern object.
Definition: coordinates.hpp:51
Definition: range_adaptor_closure.hpp:34