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

scalar.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_MATH_SCALAR_HPP
9 #define EAGINE_MATH_SCALAR_HPP
10 
11 #include "../type_identity.hpp"
12 #include "../vect/data.hpp"
13 #include "../vect/fill.hpp"
14 #include "fwd.hpp"
15 #include <type_traits>
16 
17 namespace eagine::math {
18 //------------------------------------------------------------------------------
23 template <typename T, int N, bool V>
24 struct scalar {
25  using type = scalar;
26 
28  using value_type = T;
29 
31  using is_vectorized = vect::has_vect_data_t<T, N, V>;
32 
33  using data_type =
34  std::conditional_t<is_vectorized::value, vect::data_t<T, N, V>, T>;
35 
36  data_type _v;
37 
38  using scalar_param = const scalar&;
39 
40  static constexpr auto _from(data_type v) noexcept {
41  return scalar{v};
42  }
43 
44  static constexpr auto _make(T v, std::true_type) noexcept {
45  return scalar{vect::fill<T, N, V>::apply(v)};
46  }
47 
48  static constexpr auto _make(T v, std::false_type) noexcept {
49  return scalar{v};
50  }
51 
53  static constexpr auto make(T v) noexcept {
54  return _make(v, is_vectorized());
55  }
56 
57  constexpr auto _get(std::true_type) const noexcept -> T {
58  return _v[0];
59  }
60 
61  constexpr auto _get(std::false_type) const noexcept -> T {
62  return _v;
63  }
64 
66  constexpr operator T() const noexcept {
67  return _get(is_vectorized());
68  }
69 
71  auto operator=(T v) noexcept -> scalar& {
72  return *this = make(v);
73  }
74 };
75 //------------------------------------------------------------------------------
76 } // namespace eagine::math
77 
78 #endif // EAGINE_MATH_SCALAR_HPP
auto operator=(T v) noexcept -> scalar &
Assignment from the value type.
Definition: scalar.hpp:71
T value_type
The scalar element type.
Definition: scalar.hpp:28
static constexpr auto make(T v) noexcept
Creates a scalar with the specified value.
Definition: scalar.hpp:53
Math-related code is placed in this namespace.
Definition: eagine.hpp:48
vect::has_vect_data_t< T, N, V > is_vectorized
Indicates if the implementation uses SIMD extensions.
Definition: scalar.hpp:31
Basic scalar implementation template.
Definition: fwd.hpp:16

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