Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use etl::size on all platforms #981

Open
jputcu opened this issue Dec 1, 2024 · 3 comments
Open

Unable to use etl::size on all platforms #981

jputcu opened this issue Dec 1, 2024 · 3 comments

Comments

@jputcu
Copy link
Contributor

jputcu commented Dec 1, 2024

I wanted to replace my sizeof(array)/sizeof(array[0]) with a standard std::size(array).

ETL provides etl::size(array) for my AVR because I don't have an STL, however, the same code should also compile on my PC which uses STL, then I don't get etl::size(array).

Current workaround is using ETL_ARRAY_SIZE.

I think the cleanest solution would be to only provide std::size(array) for non-stl targets. I know this is a sensitive subject but if something is implemented exactly the same:

  • giving it the same name doesn't need documentation (maybe just a link)
  • I don't need macro magic to make my library work without ETL
  • no ETL_OR_STD
  • every C++ developer will recognize the function.

(I think etl::move, etl::forward,... would also benefit from this).

@jwellbelove
Copy link
Contributor

There are a few ETL functions that have this issue, and it's down to 'Argument Dependent Lookup' (ADL) rules.

What happens is that the compiler would see both the STL's and the ETL's variant of the function and complain about an ambiguous function call.

The functions that can suffer from this are swap, begin, end, size (there may be one or two others).

Putting these into the std name space would solve the problem, but break backwards compatibility, as the ETL versions could not exist at the same time.

@jputcu
Copy link
Contributor Author

jputcu commented Dec 1, 2024

It would be nice to only include a specific subdirectory containing std items for the non-stl targets.

@jwellbelove
Copy link
Contributor

jwellbelove commented Dec 1, 2024

The full list of STL/ETL items that need ETL_OR_STD are:-

swap
pair
begin
cbegin
end
cend
size
make_pair
reverse_iterator
input_iterator_tag
output_iterator_tag
forward_iterator_tag
bidirectional_iterator_tag
random_access_iterator_tag

etl::move, etl::forward etc don't have the same problem as they do not get custom overloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants