Skip to content

Commit

Permalink
Experiment with constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed May 17, 2018
1 parent d63a8b6 commit 53c52ad
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion asdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ YAML::Node yaml_encode(byteorder_t byteorder);
// }

constexpr uint16_t byteorder_magic = 1;
// struct uchar2_t {
// unsigned char ch[2];
// };
constexpr byteorder_t host_byteorder() {
return *reinterpret_cast<const uint8_t *>(&byteorder_magic) == 1
// return *reinterpret_cast<const unsigned char *>(&byteorder_magic) == 1
// ? byteorder_t::little
// : byteorder_t::big;
return reinterpret_cast<const array<unsigned char, 2> &>(
byteorder_magic)[0] == 1
? byteorder_t::little
: byteorder_t::big;
// return reinterpret_cast<unsigned char[2]>(byteorder_magic)[0] == 1
// ? byteorder_t::little
// : byteorder_t::big;
// return reinterpret_cast<uchar2_t>(byteorder_magic).ch[0] == 1
// ? byteorder_t::little
// : byteorder_t::big;
}

// Convert to host byte order
Expand Down

0 comments on commit 53c52ad

Please sign in to comment.