summaryrefslogtreecommitdiffhomepage
path: root/src/recode.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-12-05 20:25:51 +0100
committerRoland Reichwein <mail@reichwein.it>2021-12-05 20:25:51 +0100
commit40526eb7f247fdfc9d08c39ed3eaa97844b3c448 (patch)
treea0dcb4af00ab2027fd0b7d3f6cac38bb55b6da55 /src/recode.cpp
parent6dcbe207ac96fcf1a73ad6504dd7d6046d8df0cc (diff)
Fix build on C++20, testsv1.5
Diffstat (limited to 'src/recode.cpp')
-rw-r--r--src/recode.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/recode.cpp b/src/recode.cpp
index 8145fb8..89bd69b 100644
--- a/src/recode.cpp
+++ b/src/recode.cpp
@@ -4,7 +4,9 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/endian/conversion.hpp>
+#include <boost/version.hpp>
+#include <algorithm>
#include <filesystem>
#include <functional>
#include <iostream>
@@ -58,10 +60,27 @@ std::string get_id()
return get_id(std::string{typeid(From).name()}, typeid(To).name());
}
+// workaround for broken boost::endian::endian_reverse_inplace for C++20 in boost 1.74
+template<typename T>
+void reverse_endian_inplace(T& c)
+{
+ size_t size{sizeof(T)};
+ uint8_t* p{reinterpret_cast<uint8_t*>(&c)};
+ for (int i = 0; i < size / 2; i++) {
+ std::swap(p[i], p[size - 1 - i]);
+ }
+}
+
template<typename T>
void reverse_endian(std::basic_string<T>& s)
{
- std::for_each(s.begin(), s.end(), [](T& c){boost::endian::endian_reverse_inplace(c);});
+ std::for_each(s.begin(), s.end(), [](T& c){
+#if BOOST_VERSION > 107400
+ boost::endian::endian_reverse_inplace(c);
+#else
+ reverse_endian_inplace(c);
+#endif
+ });
}
std::unordered_map<std::string, std::function<std::string(const std::string&, bool, bool)>> convert_map {};