feat(math): add with_storage template to tensor

This commit is contained in:
2026-11-01 09:59:06 +01:00
parent 3dfcb754f8
commit 75243e9d08
3 changed files with 28 additions and 0 deletions
+22
View File
@@ -73,6 +73,25 @@ struct is_tensor_dynamic<tensor<T, dynamic_extent, Rest...>> : std::true_type {}
template <typename T>
static constexpr auto is_tensor_dynamic_v = is_tensor_dynamic<T>::value;
namespace detail {
template <typename>
struct tensor_with_storage {};
template <>
struct tensor_with_storage<heap_storage_tag> {
template <typename T, std::size_t... Dims>
using type = tensor<detach_storage_t<T>, Dims...>;
};
template <>
struct tensor_with_storage<inline_storage_tag> {
template <typename T, std::size_t... Dims>
using type = tensor<inline_storage<detach_storage_t<T>>, Dims...>;
};
} // namespace detail
template <typename T>
struct tensor_traits {};
@@ -91,6 +110,9 @@ struct tensor_traits<tensor<T, Dims...>> {
static constexpr std::enable_if_t<(sizeof...(Dims) > 0), std::size_t[sizeof...(Dims)]> dimensions = { Dims... };
static constexpr std::size_t size = dynamic ? dynamic_extent : (Dims * ... * 1);
template <typename ST>
using with_storage_t = typename detail::tensor_with_storage<ST>::type;
};
} // namespace math