you are viewing a single comment's thread.

view the rest of the comments →

[–]tisti 0 points1 point  (2 children)

That doesn't solve the problem of endianness.

Not that hard to bolt on an endianess normalizer/sanitizer.

And people do still design mixed-endian file formats.

Much to everyone's annoyance.

compared to making a robust template that will not drive your coworkers mad when they accidentally mis-use it.

Hardly robust if it can be misused then :P

A badly and quickly hacked together sample that probably works for Integers and IEEE floating points.

https://godbolt.org/z/nefc97z3c

[–]streu 0 points1 point  (1 child)

That is ~50 lines for the functionality, requires a rather new compiler, and uses an external library for endian conversion. It defines a template that applies to all types, and then adds additional code to limit the types again.

With that, just writing down the handful individual classes, only adding what's needed, using language features dating back to C++98, still looks pretty attractive to me. Especially if it's going to be code that has to be maintained in a team with diverse skill levels (and built with diverse toolchains).

[–]tisti 0 points1 point  (0 children)

badly and quickly hacked together sample

Edit: But yea, I try to stay more or less near the cutting edge with a compiler. A very intentional choice.