Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matt77hias committed Sep 13, 2018
1 parent 306d8bf commit ed8d0c3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions MAGE/Utilities/src/collection/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace mage {
namespace details {

template< typename ActionT, typename FromT, size_t...I >
[[nodiscard]]
constexpr const auto TransformArray(ActionT&& action,
const std::array< FromT, sizeof...(I) >& a,
std::index_sequence< I... >) {
Expand All @@ -32,27 +33,31 @@ namespace mage {
}

template< typename T, size_t...I >
[[nodiscard]]
constexpr const auto FillArray(const T& value,
std::index_sequence< I... >) {

return std::array< T, sizeof...(I) >{ (static_cast< void >(I), value)... };
}

template< size_t ToN, typename T, size_t...I >
[[nodiscard]]
constexpr const auto EnlargeArray(const std::array< T, sizeof...(I) >& a,
std::index_sequence< I... >) {

return std::array< T, ToN >{ a[I]... };
}

template< typename T, typename TupleT, std::size_t... I >
[[nodiscard]]
constexpr const auto TuppleToArray(const TupleT& t,
std::index_sequence< I... >) {

return std::array< T, sizeof...(I) >{ std::get< I >(t)... };
}

template< typename T, size_t...I >
[[nodiscard]]
constexpr const auto ArrayToTupple(const std::array< T, sizeof...(I) >& a,
std::index_sequence< I... >) noexcept {

Expand All @@ -61,6 +66,7 @@ namespace mage {
}

template< typename ActionT, typename FromT, size_t N >
[[nodiscard]]
constexpr const auto TransformArray(ActionT&& action,
const std::array< FromT, N >& a) {

Expand All @@ -69,6 +75,7 @@ namespace mage {
}

template< typename ToT, typename FromT, size_t N >
[[nodiscard]]
constexpr const auto StaticCastArray(const std::array< FromT, N >& a) {
constexpr auto f = [](const FromT& v) {
return static_cast< ToT >(v);
Expand All @@ -77,22 +84,26 @@ namespace mage {
}

template< typename T, size_t N >
[[nodiscard]]
constexpr const auto FillArray(const T& value) {
return details::FillArray(value, std::make_index_sequence< N >());
}

template< size_t ToN, typename T, size_t FromN >
[[nodiscard]]
constexpr const auto EnlargeArray(const std::array< T, FromN >& a) {
return details::EnlargeArray< ToN >(a, std::make_index_sequence< FromN >());
}

template< typename T, typename... Ts >
[[nodiscard]]
constexpr const auto TuppleToArray(const std::tuple< T, Ts... >& t) {
constexpr auto N = sizeof...(Ts) + 1u;
return details::TuppleToArray< T >(t, std::make_index_sequence< N >());
}

template< typename T, size_t N >
[[nodiscard]]
constexpr const auto ArrayToTupple(const std::array< T, N >& a) {
return details::ArrayToTupple(a, std::make_index_sequence< N >());
}
Expand Down

0 comments on commit ed8d0c3

Please sign in to comment.