diff options
author | Lee Clagett <code@leeclagett.com> | 2017-03-09 15:50:51 -0500 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2017-04-11 16:35:14 -0400 |
commit | 93e10f1cc40f31aa4fd10ed09a42cc9caa3bdd8c (patch) | |
tree | 27b42a557478acdee579b1f0ce649ca06218c1fc /contrib/epee/include/hex.h | |
parent | Improvements for epee binary to hex functions: (diff) | |
download | monero-93e10f1cc40f31aa4fd10ed09a42cc9caa3bdd8c.tar.xz |
Simplified the implementation and features of span
Diffstat (limited to 'contrib/epee/include/hex.h')
-rw-r--r-- | contrib/epee/include/hex.h | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/contrib/epee/include/hex.h b/contrib/epee/include/hex.h index 99a86503a..f8d6be048 100644 --- a/contrib/epee/include/hex.h +++ b/contrib/epee/include/hex.h @@ -33,46 +33,33 @@ #include <iosfwd> #include <string> -#include "span_view.h" +#include "span.h" namespace epee { struct to_hex { //! \return A std::string containing hex of `src`. - static std::string string(const view<std::uint8_t> src); - - //! \return A std::string containing hex of `src`. - static std::string string(const view<char> src) { - return string(view_cast<std::uint8_t>(src)); - } + static std::string string(const span<const std::uint8_t> src); //! \return An array containing hex of `src`. template<std::size_t N> - static std::array<char, N * 2> - array(const std::array<std::uint8_t, N>& src) noexcept(noexcept(view<std::uint8_t>(src))) + static std::array<char, N * 2> array(const std::array<std::uint8_t, N>& src) noexcept { std::array<char, N * 2> out{{}}; static_assert(N <= 128, "keep the stack size down"); - buffer_unchecked(out.data(), src); + buffer_unchecked(out.data(), {src.data(), src.size()}); return out; } //! Append `src` as hex to `out`. - static void buffer(std::ostream& out, const view<std::uint8_t> src); + static void buffer(std::ostream& out, const span<const std::uint8_t> src); //! Append `< + src + >` as hex to `out`. - static void formatted(std::ostream& out, const view<std::uint8_t> src); - - //! Append `< + src + >` as hex to `out`. - template<typename T> - static void formatted_from_pod(std::ostream& out, const T& pod) - { - formatted(out, pod_cast<const std::uint8_t>(pod)); - } + static void formatted(std::ostream& out, const span<const std::uint8_t> src); private: //! Write `src` bytes as hex to `out`. `out` must be twice the length - static void buffer_unchecked(char* out, const view<std::uint8_t> src) noexcept; + static void buffer_unchecked(char* out, const span<const std::uint8_t> src) noexcept; }; } |