[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master e46bec4 1/4: Assert endianness [381]
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master e46bec4 1/4: Assert endianness [381] |
Date: |
Wed, 6 Jun 2018 18:55:31 -0400 (EDT) |
branch: master
commit e46bec4aa41a04806b82114f4ccf8ebe18395e1f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Assert endianness [381]
Incidentally moved all static assertions to ctor.
---
actuarial_table.cpp | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/actuarial_table.cpp b/actuarial_table.cpp
index 17bf1c0..81ba5e4 100644
--- a/actuarial_table.cpp
+++ b/actuarial_table.cpp
@@ -43,6 +43,7 @@
#include <ios>
#include <istream>
#include <limits>
+#include <type_traits> // endian
namespace
{
@@ -90,6 +91,17 @@ actuarial_table::actuarial_table(std::string const&
filename, int table_number)
,max_select_age_ (-1)
,table_offset_ (-1)
{
+ // Binary tables in the SOA format are not portable; this code
+ // presumably works only on little-endian hardware.
+#if 201900L < __cplusplus
+ #error Use the proper C++20 value, which was unknown when this was written.
+ static_assert(std::endian::native == std::endian::little);
+#endif // 201900L < __cplusplus
+
+ static_assert(8 == CHAR_BIT);
+ static_assert(4 == sizeof(int));
+ static_assert(2 == sizeof(short int));
+
if(table_number_ <= 0)
{
alarum()
@@ -211,13 +223,6 @@ void actuarial_table::find_table()
;
}
- // TODO ?? Assert endianness too? SOA tables are not portable;
- // probably they can easily be read only on x86 hardware.
-
- static_assert(8 == CHAR_BIT);
- static_assert(4 == sizeof(int));
- static_assert(2 == sizeof(short int));
-
// 27.4.3.2/2 requires that this be interpreted as invalid.
// Reinitialize it here for robustness, even though the ctor
// already initializes it in the same way.