ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.05k stars 372 forks source link

Fixed Extent etl::span ambiguous function overloads #826

Closed omar-droubi closed 2 months ago

omar-droubi commented 5 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:

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.

jwellbelove commented 2 months ago

Fixed 20.38.11