Simplified the implementation and features of span

This commit is contained in:
Lee Clagett 2017-03-09 15:50:51 -05:00
parent 4a8f96f95d
commit 93e10f1cc4
7 changed files with 169 additions and 208 deletions

View file

@ -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;
};
}