Closed omar-droubi closed 2 months ago
With the fix for #753, Function overloading based on the Extent of a fixed extent etl::span no longer works. This was caused by the introduction of etl::span constructors were the parameters are a container with .data() and size() fields.
void f(etl::span<uint8_t, 8> b){ std::cout << "f with etl::span<uint8_t, 8>" << std::endl; } void f(etl::span<uint8_t, 16> b){ std::cout << "f with etl::span<uint8_t, 16>" << std::endl; } int main() { etl::array<uint8_t, 8> arr8; etl::array<uint8_t, 16> arr16; f(arr8); f(arr16); return 0; }
The above code doesn't compile for ETL. If I change to std::span, then compilation is fine.
main.cpp:21:5: error: call to 'f' is ambiguous f(arr8); ^ main.cpp:9:6: note: candidate function void f(etl::span<uint8_t, 8> b){ ^ main.cpp:13:6: note: candidate function void f(etl::span<uint8_t, 16> b){ ^ main.cpp:22:5: error: call to 'f' is ambiguous f(arr16); ^ main.cpp:9:6: note: candidate function void f(etl::span<uint8_t, 8> b){ ^ main.cpp:13:6: note: candidate function void f(etl::span<uint8_t, 16> b){ ^ 2 errors generated.
A fix for this is as follows:
template<typename T> struct is_std_array : false_type {}; template<typename T, size_t N> struct is_std_array<etl::array<T, N>> : true_type {};
template <typename TContainer, typename = typename etl::enable_if<!etl::is_pointer<etl::remove_reference_t<TContainer>>::value && !etl::is_array<etl::remove_reference_t<TContainer>>::value&& !etl::is_std_array<etl::remove_reference_t<TContainer>>::value&& etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type> ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) { }
I don't know if such a fix is acceptable, or would it cause issue for the issue in #753.
This only applies to fixed extent etl::span.
Fixed 20.38.11
With the fix for #753, Function overloading based on the Extent of a fixed extent etl::span no longer works. This was caused by the introduction of etl::span constructors were the parameters are a container with .data() and size() fields.
The above code doesn't compile for ETL. If I change to std::span, then compilation is fine.
A fix for this is as follows:
I don't know if such a fix is acceptable, or would it cause issue for the issue in #753.
This only applies to fixed extent etl::span.