22 #ifndef PLAYRHO_COMMON_VECTOR_HPP
23 #define PLAYRHO_COMMON_VECTOR_HPP
27 #include <type_traits>
47 template <
typename T, std::
size_t N>
89 template<
typename... Tail>
91 Tail... tail) noexcept:
elements{head, T(tail)...}
159 assert(pos <
size());
168 assert(pos <
size());
237 template <
typename T, std::
size_t N>
244 template <
typename T, std::
size_t N>
247 for (
auto i = decltype(N){0}; i < N; ++i)
249 if (lhs[i] != rhs[i])
259 template <
typename T, std::
size_t N>
262 return !(lhs == rhs);
267 template <
typename T, std::
size_t N>
269 std::enable_if_t<std::is_same<T, decltype(+T{})>::value, Vector<T, N>>
277 template <
typename T, std::
size_t N>
279 std::enable_if_t<std::is_same<T, decltype(-T{})>::value, Vector<T, N>>
282 for (
auto i = decltype(N){0}; i < N; ++i)
291 template <
typename T, std::
size_t N>
293 std::enable_if_t<std::is_same<T, decltype(T{} + T{})>::value, Vector<T, N>&>
296 for (
auto i = decltype(N){0}; i < N; ++i)
305 template <
typename T, std::
size_t N>
307 std::enable_if_t<std::is_same<T, decltype(T{} - T{})>::value, Vector<T, N>&>
310 for (
auto i = decltype(N){0}; i < N; ++i)
319 template <
typename T, std::
size_t N>
321 std::enable_if_t<std::is_same<T, decltype(T{} + T{})>::value, Vector<T, N>>
329 template <
typename T, std::
size_t N>
331 std::enable_if_t<std::is_same<T, decltype(T{} - T{})>::value, Vector<T, N>>
339 template <
typename T1,
typename T2, std::
size_t N>
341 std::enable_if_t<std::is_same<T1, decltype(T1{} * T2{})>::value, Vector<T1, N>&>
344 for (
auto i = decltype(N){0}; i < N; ++i)
353 template <
typename T1,
typename T2, std::
size_t N>
355 std::enable_if_t<std::is_same<T1, decltype(T1{} / T2{})>::value, Vector<T1, N>&>
358 const auto inverseRhs =
Real{1} / rhs;
359 for (
auto i = decltype(N){0}; i < N; ++i)
361 lhs[i] *= inverseRhs;
384 template <
typename T1,
typename T2, std::size_t A, std::size_t B, std::size_t C,
385 typename OT = decltype(T1{} * T2{})>
387 std::enable_if_t<IsMultipliable<T1, T2>::value, Vector<Vector<OT, C>, A>>
392 for (
auto a = decltype(A){0}; a < A; ++a)
394 for (
auto c = decltype(C){0}; c < C; ++c)
403 for (
auto b = decltype(B){0}; b < B; ++b)
405 element += lhs[a][b] * rhs[b][c];
407 result[a][c] = element;
420 template <
typename T1,
typename T2, std::size_t A, std::size_t B,
421 typename OT = decltype(T1{} * T2{})>
423 std::enable_if_t<IsMultipliable<T1, T2>::value && !IsVector<T1>::value, Vector<OT, B>>
427 for (
auto b = decltype(B){0}; b < B; ++b)
430 for (
auto a = decltype(A){0}; a < A; ++a)
432 element += lhs[a] * rhs[a][b];
446 template <
typename T1,
typename T2, std::size_t A, std::size_t B,
447 typename OT = decltype(T1{} * T2{})>
449 std::enable_if_t<IsMultipliable<T1, T2>::value && !IsVector<T2>::value, Vector<OT, B>>
453 for (
auto b = decltype(B){0}; b < B; ++b)
456 for (
auto a = decltype(A){0}; a < A; ++a)
458 element += lhs[b][a] * rhs[a];
469 template <std::size_t N,
typename T1,
typename T2,
typename OT = decltype(T1{} * T2{})>
471 std::enable_if_t<IsMultipliable<T1, T2>::value && !IsVector<T1>::value, Vector<OT, N>>
476 for (
auto i = decltype(N){0}; i < N; ++i)
478 result[i] = s * a[i];
487 template <std::size_t N,
typename T1,
typename T2,
typename OT = decltype(T1{} * T2{})>
489 std::enable_if_t<IsMultipliable<T1, T2>::value && !IsVector<T2>::value, Vector<OT, N>>
494 for (
auto i = decltype(N){0}; i < N; ++i)
496 result[i] = a[i] * s;
503 template <std::size_t N,
typename T1,
typename T2,
typename OT = decltype(T1{} / T2{})>
505 std::enable_if_t<IsDivisable<T1, T2>::value && !IsVector<T2>::value, Vector<OT, N>>
510 const auto inverseS =
Real{1} / s;
511 for (
auto i = decltype(N){0}; i < N; ++i)
513 result[i] = a[i] * inverseS;
520 template <std::
size_t I, std::
size_t N,
typename T>
523 static_assert(I < N,
"Index out of bounds in playrho::get<> (playrho::Vector)");
528 template <std::
size_t I, std::
size_t N,
typename T>
531 static_assert(I < N,
"Index out of bounds in playrho::get<> (playrho::Vector)");
537 template <
typename T, std::
size_t N>
541 for (
auto i = decltype(N){0}; i < N; ++i)
543 if (i > decltype(N){0})
558 template<
class T, std::
size_t N>
559 class tuple_size< playrho::Vector<T, N> >:
public std::integral_constant<std::size_t, N> {};
562 template<std::
size_t I,
class T, std::
size_t N>
572 #endif // PLAYRHO_COMMON_VECTOR_HPP