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

view.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_VECT_VIEW_HPP
9 #define EAGINE_VECT_VIEW_HPP
10 
11 #include "../span.hpp"
12 #include "data.hpp"
13 
14 namespace eagine::vect {
15 
16 template <typename T, int N, bool V>
17 struct view {
18 private:
19  static auto _addr(const data_t<T, N, V>& d, std::false_type) noexcept
20  -> const T* {
21  return static_cast<const T*>(d._v);
22  }
23 
24  static auto _addr(const data_t<T, N, V>& d, std::true_type) noexcept
25  -> const T* {
26  // TODO: strict aliasing, launder?
27  return reinterpret_cast<const T*>(&d);
28  }
29 
30 public:
31  static auto apply(const data_t<T, N, V>& d) noexcept -> span<const T> {
32  static_assert(sizeof(T[N]) == sizeof(data_t<T, N, V>));
33  return {_addr(d, has_vect_data<T, N, V>()), N};
34  }
35 
36  template <int M>
37  static auto apply(const data_t<T, N, V> (&d)[M]) noexcept -> span<const T> {
38  static_assert(sizeof(T[N][M]) == sizeof(data_t<T, N, V>[M]));
39  return {_addr(d[0], has_vect_data<T, N, V>()), N * M};
40  }
41 };
42 
43 } // namespace eagine::vect
44 
45 #endif // EAGINE_VECT_VIEW_HPP
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458

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