Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
STYLE: Clean-up ByteSwapper, using private
SwapBytes
helper function #4855base: master
Are you sure you want to change the base?
STYLE: Clean-up ByteSwapper, using private
SwapBytes
helper function #4855Changes from all commits
d44f513
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a run-time exception for a "constexpr" conditional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! Only the condition of an
if constexpr (condition) { ... }
must be evaluated at compile-time. Anything inside theif
orelse
clause may be evaluated at run-time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this exception, we might also just trigger a compile-time assert failure (
static_assert
). But obviously, that would change the behavior of ByteSwapper (at least for an unsupported number of bytes). It might be considered an improvement, to replace the exception with astatic_assert
, of course. Would you like that?We might just do:
Would you like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think it would be an improvement and help detect errors in code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it would be fine to me to also support other number of bytes. Why not support
numberOfBytes == 16
, for example? For example, when a user wants to swap 128-bit integers...!I think the original
itkGenericExceptionMacro("Cannot swap number of bytes requested")
was there just because we only had three of those helper functions:Swap2
,Swap4
, andSwap8
. Instead, we can now support just any number of bytes! Would you like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still broken, now it's itkVTKPolyDataMeshIO, at https://open.cdash.org/viewBuildError.php?type=1&buildid=9915657:
So would you also want us to drop
long double
support fromitk::VTKPolyDataMeshIO
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsurprisingly, this endian swapping only affects IO classes.
As the other float types are being swapped, why not swap
long double
as well? Just add size of thelong double
to the list of the allowed sizes in the assert? @blowekamp what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quick google said 128-bit float may be an abnormal case:
https://www.talospace.com/2018/12/the-saga-of-power-isa-128-bit-long.html
So... Just leave it as a run time exception of now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be fine to me to restore the
itkGenericExceptionMacro("Cannot swap number of bytes requested")
that I originally proposed, and remove the compile-time static_assert(numberOfBytes is 2 or 4 or 8).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should leave support for
long double
if there is no need for endian swapping (the usual case).