From 2dd85adc527e3172ee4c4f4814703f3e9f9f72ed Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sat, 29 Oct 2022 19:46:39 +0800 Subject: [PATCH] add: [imp] comments --- include/libimp/span.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/libimp/span.h b/include/libimp/span.h index c686f8d..d2596bb 100644 --- a/include/libimp/span.h +++ b/include/libimp/span.h @@ -56,7 +56,7 @@ using is_sized_sentinel_for = /// @brief Obtain the address represented by p /// without forming a reference to the object pointed to by p. -/// @see https://en.cppreference.com/w/cpp/memory/to_address +/// @see https://en.cppreference.com/w/cpp/memory/to_address template constexpr T *to_address(T *ptr) noexcept { @@ -217,12 +217,19 @@ bool operator==(span a, span b) noexcept { return true; } +/// @brief Converts a span into a view of its underlying bytes. +/// @see https://en.cppreference.com/w/cpp/container/span/as_bytes + template ::value, std::uint8_t const, std::uint8_t>::type> auto as_bytes(span s) noexcept -> span { return {reinterpret_cast(s.data()), s.size_bytes()}; } +/// @brief Constructs an object of type T and wraps it in a span. +/// Before C++17, template argument deduction for class templates was not supported. +/// @see https://en.cppreference.com/w/cpp/language/template_argument_deduction + template auto make_span(T *arr, std::size_t count) noexcept -> span { return {arr, count};