basic qua detail functions

This commit is contained in:
BlackMATov
2021-01-25 05:46:37 +07:00
parent 1d8ffaaa34
commit 41c21078da
2 changed files with 121 additions and 0 deletions

View File

@@ -13,6 +13,48 @@
namespace vmath_hpp::detail::impl
{
template < typename A, typename F, std::size_t... Is >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join_impl(
F&& f,
const qua<A>& a,
std::index_sequence<Is...>
) -> qua<decltype(f(
std::declval<A>()))>
{
return { f(a[Is])... };
}
template < typename A, typename B, typename F, std::size_t... Is >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join_impl(
F&& f,
const qua<A>& a,
const qua<B>& b,
std::index_sequence<Is...>
) -> qua<decltype(f(
std::declval<A>(),
std::declval<B>()))>
{
return { f(a[Is], b[Is])... };
}
template < typename A, typename B, typename C, typename F, std::size_t... Is >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join_impl(
F&& f,
const qua<A>& a,
const qua<B>& b,
const qua<C>& c,
std::index_sequence<Is...>
) -> qua<decltype(f(
std::declval<A>(),
std::declval<B>(),
std::declval<C>()))>
{
return { f(a[Is], b[Is], c[Is])... };
}
template < typename A, typename B, typename F, std::size_t... Is >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto fold_join_impl(
@@ -35,10 +77,54 @@ namespace vmath_hpp::detail::impl
) -> A {
return ((init = f(std::move(init), b[Is], c[Is])), ...);
}
template < typename A, typename F, std::size_t I, std::size_t... Is >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto fold1_join_impl(
F&& f,
const qua<A>& a,
std::index_sequence<I, Is...>
) -> A {
A init = a[I];
return ((init = f(std::move(init), a[Is])), ...);
}
}
namespace vmath_hpp::detail
{
template < typename A, typename F >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join(
F&& f,
const qua<A>& a
) {
return impl::map_join_impl(
std::forward<F>(f), a, std::make_index_sequence<4>{});
}
template < typename A, typename B, typename F >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join(
F&& f,
const qua<A>& a,
const qua<B>& b
) {
return impl::map_join_impl(
std::forward<F>(f), a, b, std::make_index_sequence<4>{});
}
template < typename A, typename B, typename C, typename F >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto map_join(
F&& f,
const qua<A>& a,
const qua<B>& b,
const qua<C>& c
) {
return impl::map_join_impl(
std::forward<F>(f), a, b, c, std::make_index_sequence<4>{});
}
template < typename A, typename B, typename F >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto fold_join(
@@ -61,6 +147,16 @@ namespace vmath_hpp::detail
return impl::fold_join_impl(
std::forward<F>(f), std::move(init), b, c, std::make_index_sequence<4>{});
}
template < typename A, typename F >
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
auto fold1_join(
F&& f,
const qua<A>& a
) {
return impl::fold1_join_impl(
std::forward<F>(f), a, std::make_index_sequence<4>{});
}
}
//