diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-01-27 17:26:58 -0800 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-01-27 17:26:58 -0800 |
commit | 76a6a794f99e7539e2e2d0a298b25d18197af727 (patch) | |
tree | eb6c3cac6d2418985505498dafc70fbc11de301c /contrib | |
parent | Merge pull request #3151 (diff) | |
parent | Remove is_pod trait, and replace with is_standard_layout requirement (diff) | |
download | monero-76a6a794f99e7539e2e2d0a298b25d18197af727.tar.xz |
Merge pull request #2969
95171614 Remove is_pod trait, and replace with is_standard_layout requirement (Lee Clagett)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/include/memwipe.h | 16 | ||||
-rw-r--r-- | contrib/epee/include/span.h | 2 | ||||
-rw-r--r-- | contrib/epee/include/string_tools.h | 9 |
3 files changed, 15 insertions, 12 deletions
diff --git a/contrib/epee/include/memwipe.h b/contrib/epee/include/memwipe.h index 6e50944e6..0d8f491b7 100644 --- a/contrib/epee/include/memwipe.h +++ b/contrib/epee/include/memwipe.h @@ -67,18 +67,14 @@ namespace tools { } }; + template<typename T> + T& unwrap(scrubbed<T>& src) { return src; } + + template<typename T> + const T& unwrap(scrubbed<T> const& src) { return src; } + template <class T, size_t N> using scrubbed_arr = scrubbed<std::array<T, N>>; } // namespace tools -// Partial specialization for std::is_pod<tools::scrubbed<T>> so that it can -// pretend to be the containted type in those contexts. -namespace std -{ - template<class t_scrubbee> - struct is_pod<tools::scrubbed<t_scrubbee>> { - static const bool value = is_pod<t_scrubbee>::value; - }; -} - #endif // __cplusplus diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h index 4273828d1..452cc088f 100644 --- a/contrib/epee/include/span.h +++ b/contrib/epee/include/span.h @@ -108,7 +108,7 @@ namespace epee template<typename T> constexpr bool has_padding() noexcept { - return !std::is_pod<T>::value || alignof(T) != 1; + return !std::is_standard_layout<T>() || alignof(T) != 1; } //! \return Cast data from `src` as `span<const std::uint8_t>`. diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 5a1ef0743..63705e401 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -45,6 +45,7 @@ #include <boost/lexical_cast.hpp> #include <boost/algorithm/string/predicate.hpp> #include "hex.h" +#include "memwipe.h" #include "span.h" #include "warnings.h" @@ -330,7 +331,7 @@ POP_WARNINGS template<class t_pod_type> std::string pod_to_hex(const t_pod_type& s) { - static_assert(std::is_pod<t_pod_type>::value, "expected pod type"); + static_assert(std::is_standard_layout<t_pod_type>(), "expected standard layout type"); return to_hex::string(as_byte_span(s)); } //---------------------------------------------------------------------------- @@ -351,6 +352,12 @@ POP_WARNINGS return true; } //---------------------------------------------------------------------------- + template<class t_pod_type> + bool hex_to_pod(const std::string& hex_str, tools::scrubbed<t_pod_type>& s) + { + return hex_to_pod(hex_str, unwrap(s)); + } + //---------------------------------------------------------------------------- bool validate_hex(uint64_t length, const std::string& str); //---------------------------------------------------------------------------- inline std::string get_extension(const std::string& str) |