Add generic swizzling function
This commit is contained in:
parent
b2012aaa77
commit
2a04f0d421
1 changed files with 31 additions and 0 deletions
31
libs/geom/include/psemek/geom/swizzle.hpp
Normal file
31
libs/geom/include/psemek/geom/swizzle.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace psemek::geom
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct swizzle_rebind;
|
||||||
|
|
||||||
|
template <template <typename, std::size_t> typename C, typename T, std::size_t N>
|
||||||
|
struct swizzle_rebind<C<T, N>>
|
||||||
|
{
|
||||||
|
template <std::size_t M>
|
||||||
|
using type = C<T, M>;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t ... I>
|
||||||
|
constexpr auto swizzle = [](auto const & x){
|
||||||
|
using result = typename detail::swizzle_rebind<std::decay_t<decltype(x)>>::template type<sizeof...(I)>;
|
||||||
|
return result{(I == (-1) ? 0 : x[I])...};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue