12 #ifndef SST_CORE_SERIALIZATION_IMPL_GET_ARRAY_SIZE_H 13 #define SST_CORE_SERIALIZATION_IMPL_GET_ARRAY_SIZE_H 15 #ifndef SST_INCLUDING_SERIALIZER_H 17 "The header file sst/core/serialization/impl/get_array_size.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serializer.h" 23 #include <type_traits> 28 template <
typename SIZE_T>
29 std::enable_if_t<std::is_integral_v<SIZE_T>,
size_t>
30 get_array_size(SIZE_T size,
const char* msg)
33 if constexpr ( std::is_unsigned_v<SIZE_T> )
34 range_error = size > SIZE_MAX;
35 else if constexpr (
sizeof(SIZE_T) >
sizeof(
size_t) )
36 range_error = size < 0 || size >
static_cast<SIZE_T
>(SIZE_MAX);
38 range_error = size < 0;
39 if ( range_error )
throw std::range_error(msg);
40 return static_cast<size_t>(size);
45 #endif // SST_CORE_SERIALIZATION_IMPL_GET_ARRAY_SIZE_H