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

esum.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_VECT_ESUM_HPP
9 #define EAGINE_VECT_ESUM_HPP
10 
11 #include "config.hpp"
12 #if EAGINE_VECT_OPTS
13 #include "hsum.hpp"
14 #else
15 #include "data.hpp"
16 #endif
17 
18 namespace eagine::vect {
19 
20 template <typename T, int N, bool V>
21 struct esum {
22 private:
23  using _dpT = data_param_t<T, N, V>;
24 
25  template <int U>
26  using _int = int_constant<U>;
27 
28  template <bool B>
29  using _bool = bool_constant<B>;
30 
31  template <int M, bool B>
32  static auto _hlp(_dpT v, _int<M>, _bool<B>) noexcept -> T {
33  static_assert(M == N);
34  T r = T(0);
35 
36  for(int i = 0; i < N; ++i) {
37  r += v[i];
38  }
39  return r;
40  }
41 
42 #if EAGINE_VECT_OPTS
43  template <bool B>
44  static constexpr auto _hlp(_dpT v, _int<1>, _bool<B>) noexcept -> T {
45  return v[0];
46  }
47 
48  template <int M>
49  static auto _hlp(_dpT v, _int<M>, std::true_type) noexcept -> T {
50  static_assert(M == N);
51  return hsum<T, N, V>::apply(v)[N - 1];
52  }
53 #endif
54 public:
55  static auto apply(_dpT v) noexcept -> T {
56  return _hlp(v, _int<N>(), has_vect_data<T, N, V>());
57  }
58 };
59 
60 } // namespace eagine::vect
61 
62 #endif // EAGINE_VECT_ESUM_HPP

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