[wpiutil] Add ArrayRef/std::span/wpi::span implicit conversions

This commit is contained in:
Peter Johnson
2021-05-23 10:37:30 -07:00
parent bc15b953b4
commit 4426216725
3 changed files with 141 additions and 0 deletions

View File

@@ -17,6 +17,9 @@ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/n4820.pdf
#include <cstddef>
#include <cstdint>
#include <type_traits>
#if __has_include(<span>)
#include <span>
#endif
namespace wpi {
@@ -219,6 +222,12 @@ public:
: storage_(other.data(), other.size())
{}
#ifdef __cpp_lib_span
constexpr span(std::span<ElementType> other) noexcept
: storage_(other.data(), other.size())
{}
#endif
~span() noexcept = default;
constexpr span&
@@ -327,6 +336,15 @@ public:
return reverse_iterator(begin());
}
#ifdef __cpp_lib_span
constexpr operator auto() const {
return std::span < ElementType,
(Extent == dynamic_extent)
? std::dynamic_extent
: Extent > (storage_.ptr, storage_.size);
}
#endif
private:
storage_type storage_{};
};