diff --git a/src/utils/CastArray.hpp b/src/utils/CastArray.hpp index 9135489e63e08998799f9498138c61e92d1a861d..57a05cbb5f893c69ac74378c579520fe58c13a64 100644 --- a/src/utils/CastArray.hpp +++ b/src/utils/CastArray.hpp @@ -57,6 +57,19 @@ class CastArray } } + PASTIS_INLINE + CastArray(DataType& value) + : m_size (sizeof(DataType)/sizeof(CastDataType)), + m_values(reinterpret_cast<CastDataType*>(&(value))) + { + static_assert((std::is_const_v<CastDataType> and std::is_const_v<DataType>) or + (not std::is_const_v<DataType>), "CastArray cannot remove const attribute"); + static_assert(std::is_trivial_v<DataType>, "Defining CastArray from non trivial type is not allowed"); + } + + PASTIS_INLINE + CastArray(DataType&& value) = delete; + PASTIS_INLINE CastArray(const CastArray&) = default; @@ -79,4 +92,16 @@ struct cast_array_to } }; +template <typename CastDataType> +struct cast_value_to +{ + template <typename DataType> + PASTIS_INLINE + static CastArray<DataType, CastDataType> + from(DataType& value) + { + return CastArray<DataType, CastDataType>(value); + } +}; + #endif // CAST_ARRAY_HPP