OGLplus  (0.59.0) a C++ wrapper for rendering APIs

cast.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_VECT_CAST_HPP
10 #define EAGINE_VECT_CAST_HPP
11 
12 #include "fill.hpp"
13 #include <utility>
14 
15 namespace eagine::vect {
16 
17 template <typename TF, int NF, bool VF, typename TT, int NT, bool VT>
18 struct cast;
19 
20 template <typename T, int N, bool V>
21 struct cast<T, N, V, T, N, V> {
22  static constexpr auto apply(data_param_t<T, N, V> v, T) noexcept
23  -> data_t<T, N, V> {
24  return v;
25  }
26 };
27 
28 template <typename TF, int NF, bool VF, typename TT, int NT, bool VT>
29 struct cast {
30 private:
31  template <int... I>
32  using _idx_seq = std::integer_sequence<int, I...>;
33  template <int N>
34  using _make_idx_seq = std::make_integer_sequence<int, N>;
35 
36  template <int... I, int... D>
37  static constexpr auto _cast(
38  data_param_t<TF, NF, VF> v,
39  data_param_t<TT, sizeof...(D), VT> d,
40  _idx_seq<I...>,
41  _idx_seq<D...>) noexcept {
42  return data_t<TT, NT, VT>{TT(v[I])..., TT(d[D])...};
43  }
44 
45  template <int... I>
46  static constexpr auto _cast(
47  data_param_t<TF, NF, VF> v,
48  data_param_t<TT, 0U, VT>,
49  _idx_seq<I...>,
50  _idx_seq<>) noexcept {
51  return data_t<TT, NT, VT>{TT(v[I])...};
52  }
53 
54 public:
55  static constexpr auto apply(
56  data_param_t<TF, NF, VF> v,
57  data_param_t<TT, (NT > NF) ? NT - NF : 0, VT> d) noexcept {
58  using is = _make_idx_seq<(NT > NF) ? NF : NT>;
59  using ds = _make_idx_seq<(NT > NF) ? NT - NF : 0>;
60  return _cast(v, d, is(), ds());
61  }
62 
63  static constexpr auto apply(data_param_t<TF, NF, VF> v, TT d) noexcept {
64  return apply(v, fill < TT, (NT > NF) ? NT - NF : 0, VT > ::apply(d));
65  }
66 };
67 
68 } // namespace eagine::vect
69 
70 #endif // EAGINE_VECT_CAST_HPP
static auto fill(basic_span< T, P, S > spn, const V &v) -> basic_span< T, P, S >
Fills a span with copies of the specified value.
Definition: span_algo.hpp:536

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).