ETLCPP / etl

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

std::bit_cast equivalent? #809

Closed jaskij closed 6 months ago

jaskij commented 6 months ago

While I'm personally happy to use ARM's latest GNU toolchain, a lot of ETL users don't have C++20 yet. Casting between types (such as floating point numbers to an array of uint8_t) in a standard compliant way before C++20 has it's pitfalls. Porting std::bit_cast might be a good idea. Sadly, I don't believe it's possible for it be constexpr.

jwellbelove commented 6 months ago

The ETL already has one. etl::bit_cast in bit.h

If you are bit casting between same sized integrals, then etl::bit_cast is constexpr (from C++14) Otherwise it is not constexpr due to the use of memcpy.

jaskij commented 6 months ago

Ah, sorry, couldn't find it in the documentation. Great news.

jwellbelove commented 6 months ago

I'll check and update the documentation page.

jaskij commented 6 months ago

Having checked the documentation once again, it's probably my unfamiliarity with how your documentation is laid out. To be frank, it's been a while since I have used external libraries (only recently started doing it on microcontrollers), so it's entirely on me.

jwellbelove commented 6 months ago

The documentation pages need a update at some point to make the features in the ETL more 'discoverable'.

jaskij commented 6 months ago

I think what you're missing is library/section overview pages. Looking at cppreference, compare the page for the numerics library to the one for the <bit> header. You have the latter, but are missing the former.

jwellbelove commented 6 months ago

The documentation pages are created manually at the moment, but the project has grown so much over the last nine years (!!!) that I will need to look at some of the auto generation options. I used to use Doxygen in a previous job, but there are more options nowadays.

jaskij commented 6 months ago

The documentation pages are created manually at the moment, but the project has grown so much over the last nine years (!!!) that I will need to look at some of the auto generation options.

Nine years? Woah. This is a great library though, so no wonder. And writing the documentation by hand is in no way the correct solution here.

I used to use Doxygen in a previous job, but there are more options nowadays.

Yup, personally I always look for tools that can integrate this with Asciidoctor, or other good writing system. Markdown, while fine for short text like here, is really insufficient for longer technical documentation. And just now I have noticed AsciiDoxy, which combines good ol' Doxygen with Asciidoctor.

It's definitely an area I'd love to help with, as I want to look into those tools myself anyway.