-
-
Notifications
You must be signed in to change notification settings - Fork 412
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
Truncating access for etl::bitset
#774
Comments
I'll look into that. |
e.g.
|
The use case it came up in was Modbus coil/discrete encoding/decoding, which actually needs arbitrary indices. And would a byte boundary be meaningful? The one meaningful boundary I can think of is width of the interior storage type (so four-byte in your Also: thank you for maintaining this library, and for reacting quickly to issues. |
Byte boundaries could result in more optimal code. I'm going to be away for the next three weeks (climbing in Spain) so I may not be able to do much work on this until I get home again. |
Since checking for byte boundaries is very cheap, maybe it would be worth the effort of writing both versions, and using one or the other at runtime? OTOH, that increases code size. Decisions, decisions.
Enjoy your vacation! That's more important. |
I'm experimenting with a solution for this.
e.g. A
|
Looking at the API, would you consider defaulting Also, it would probably be better to actually express the integral constraint in code itself, although it would probably require adding a new macro. |
The default length is a good idea. The integral constraint is built-in with an |
The API looks good to me then. I thought a little about extraction to, say, |
BTW rather than using the C style |
…://github.com/ETLCPP/etl into feature/#774-Truncating-access-for-etl-bitset
I now have a working version of this. |
Great! Thank you! |
…://github.com/ETLCPP/etl into feature/#774-Truncating-access-for-etl-bitset # Conflicts: # include/etl/binary.h # test/run-syntax-checks.sh # test/run-tests.sh # test/test_binary.cpp
…://github.com/ETLCPP/etl into feature/#774-Truncating-access-for-etl-bitset
…elopment # Conflicts: # test/vs2022/etl.vcxproj.filters
Added 20.38.11 |
I find myself with a simple need: to extract a single byte from a fairly large
etl::bitset
. One big enough that I can not comfortably convert it to an integral variable.While there are probably workarounds using a bitset while using
uint8_t
as the underlying buffer, and usingetl::bitset::span()
, I would prefer a more ergonomic API.A possible option would be to have a
value_truncated<typename T>()
, which would returnsizeof(T) * CHAR_BIT
lowest bits of the bitset. Looking at the existingvalue<typename T>
code, it would probably look something like this:Combined with existing bitshift operators, this would allow nice, optimized, access to specific parts of a larger bitset.
The text was updated successfully, but these errors were encountered: