forcefully exclude arrays from being interpreted as pointers

This commit is contained in:
Francois Chabot 2020-05-27 18:21:38 -04:00
parent b9416a26aa
commit 377995f495
2 changed files with 24 additions and 12 deletions

View file

@ -394,6 +394,7 @@ using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const
template < typename CharT, template < typename CharT,
typename std::enable_if < typename std::enable_if <
std::is_pointer<CharT>::value and std::is_pointer<CharT>::value and
!std::is_array<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and std::is_integral<typename std::remove_pointer<CharT>::type>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1, sizeof(typename std::remove_pointer<CharT>::type) == 1,
int >::type = 0 > int >::type = 0 >
@ -404,6 +405,11 @@ contiguous_bytes_input_adapter input_adapter(CharT b)
return input_adapter(ptr, ptr + length); return input_adapter(ptr, ptr + length);
} }
template<typename T, std::size_t N>
auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
{
return input_adapter(array, array + N);
}
// This class only handles inputs of input_buffer_adapter type. // This class only handles inputs of input_buffer_adapter type.
// It's required so that expressions like {ptr, len} can be implicitely casted // It's required so that expressions like {ptr, len} can be implicitely casted

View file

@ -4816,6 +4816,7 @@ using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const
template < typename CharT, template < typename CharT,
typename std::enable_if < typename std::enable_if <
std::is_pointer<CharT>::value and std::is_pointer<CharT>::value and
!std::is_array<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and std::is_integral<typename std::remove_pointer<CharT>::type>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1, sizeof(typename std::remove_pointer<CharT>::type) == 1,
int >::type = 0 > int >::type = 0 >
@ -4826,6 +4827,11 @@ contiguous_bytes_input_adapter input_adapter(CharT b)
return input_adapter(ptr, ptr + length); return input_adapter(ptr, ptr + length);
} }
template<typename T, std::size_t N>
auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
{
return input_adapter(array, array + N);
}
// This class only handles inputs of input_buffer_adapter type. // This class only handles inputs of input_buffer_adapter type.
// It's required so that expressions like {ptr, len} can be implicitely casted // It's required so that expressions like {ptr, len} can be implicitely casted