mirror of
https://github.com/microsoft/GSL.git
synced 2025-05-12 17:05:20 -04:00
Add span construction from unique_ptr and shared_ptr
This patch adds support for std::unique_ptr and std::shared_ptr to the gsl::span class instead of having to manually grab the pointer via get(). For reference, this is part of the following issue: https://github.com/Microsoft/GSL/issues/402
This commit is contained in:
committed by
Neil MacIntosh
parent
d641796b21
commit
2b51b8767a
7
gsl/span
7
gsl/span
@ -29,6 +29,7 @@
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@ -386,6 +387,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<class ArrayElementType = std::add_pointer<element_type>>
|
||||
constexpr span(const std::unique_ptr<ArrayElementType>& ptr, index_type count) : storage_(ptr.get(), count) {}
|
||||
|
||||
constexpr span(const std::unique_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0) {}
|
||||
constexpr span(const std::shared_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0) {}
|
||||
|
||||
// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
|
||||
// on Container to be a contiguous sequence container.
|
||||
template <class Container,
|
||||
|
Reference in New Issue
Block a user