From 7dac111b025889f46bb51dfd03dffc328784fd03 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 5 Jan 2019 14:40:28 +0100 Subject: [PATCH] to work around clang issue, keyConv is now very ugly, but completely generic --- lmdb-typed.hh | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/lmdb-typed.hh b/lmdb-typed.hh index 78ef80a..63e9faa 100644 --- a/lmdb-typed.hh +++ b/lmdb-typed.hh @@ -67,38 +67,23 @@ void serFromString(const std::string& str, T& ret) */ } -// mini-serializer for keys. Again, you can override -template -std::string keyConv(const KeyType& t); -template<> -inline std::string keyConv(const std::string& t) +template +inline std::string keyConv(const T& t); + +template ::value,T>::type* = nullptr> +inline std::string keyConv(const T& t) +{ + return std::string((char*)&t, sizeof(t)); +} + +// this is how to override specific types.. it is ugly +template::value,T>::type* = nullptr> +inline std::string keyConv(const T& t) { return t; } -template<> -inline std::string keyConv(const uint32_t& t) -{ - return std::string((char*)&t, sizeof(t)); -} -template<> -inline std::string keyConv(const int32_t& t) -{ - return std::string((char*)&t, sizeof(t)); -} -template<> -inline std::string keyConv(const uint64_t& t) -{ - return std::string((char*)&t, sizeof(t)); -} -template<> -inline std::string keyConv(const int64_t& t) -{ - return std::string((char*)&t, sizeof(t)); -} - - /** This is a struct that implements index operations, but only the operations that are broadcast to all indexes.