OpenKalman
algorithm.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_COMPATIBILITY_RANGES_ALGORITHM_HPP
17 #define OPENKALMAN_COMPATIBILITY_RANGES_ALGORITHM_HPP
18 
19 #include <algorithm>
22 
24 {
25 #ifdef __cpp_lib_ranges
26  using std::ranges::in_out_result;
27  using std::ranges::copy;
28  using std::ranges::copy_result;
29 #else
30  template<typename I, typename O>
32  {
33  I in;
34  O out;
35 
36  template<typename I2, typename O2, std::enable_if_t<
37  stdex::convertible_to<const I&, I2> and
38  stdex::convertible_to<const O&, O2>, int> = 0>
39  constexpr operator
40  in_out_result<I2, O2>() const &
41  {
42  return {in, out};
43  }
44 
45  template<class I2, class O2, std::enable_if_t<
46  stdex::convertible_to<I, I2> and
47  stdex::convertible_to<O, O2>, int> = 0>
48  constexpr operator
50  {
51  return {std::move(in), std::move(out)};
52  }
53  };
54 
55 
56  template<typename I, typename O>
58 
59 
60  namespace detail
61  {
62  struct copy_fn
63  {
64  template<typename I, typename S, typename O, std::enable_if_t<
65  stdex::input_iterator<I> and
66  stdex::sentinel_for<I, S> and
67  stdex::weakly_incrementable<O> and
68  stdex::indirectly_copyable<I, O>, int> = 0>
69  constexpr copy_result<I, O>
70  operator()(I first, S last, O result) const
71  {
72  for (; first != last; ++first, (void)++result)
73  *result = *first;
74  return {std::move(first), std::move(result)};
75  }
76 
77 
78  template<typename R, typename O, std::enable_if_t<
79  input_range<R> and
80  stdex::weakly_incrementable<O> and
81  indirectly_copyable<iterator_t<R>, O>, int> = 0>
83  operator()(R&& r, O result) const
84  {
85  return (*this)(ranges::begin(r), ranges::end(r), std::move(result));
86  }
87  };
88  }
89 
90  inline constexpr detail::copy_fn copy;
91 #endif
92 
93 }
94 
95 #endif
Definition: algorithm.hpp:31
Definition: common.hpp:200
Definition: algorithm.hpp:62