Skip to content

Commit

Permalink
Specialize span c'tor for std::array of length 0, set storage to nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-hill committed Aug 21, 2018
1 parent 7d26c61 commit dd9716a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions include/gsl/span
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,27 @@ public:
: storage_(KnownNotNull{std::addressof(arr[0])}, details::extent_type<N>())
{}

template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
constexpr span(std::array<ArrayElementType, N>& arr) noexcept
: storage_(arr.data(), details::extent_type<N>())
{}
template <std::size_t N, class = std::enable_if_t<(N > 0)>>
constexpr span(std::array<std::remove_const_t<element_type>, N>& arr) noexcept
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
{
}

template <std::size_t N>
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
constexpr span(std::array<std::remove_const_t<element_type>, 0>&) noexcept
: storage_(static_cast<pointer>(nullptr), details::extent_type<0>())
{
}

template <std::size_t N, class = std::enable_if_t<(N > 0)>>
constexpr span(const std::array<std::remove_const_t<element_type>, N>& arr) noexcept
: storage_(arr.data(), details::extent_type<N>())
{}
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
{
}

constexpr span(const std::array<std::remove_const_t<element_type>, 0>&) noexcept
: storage_(static_cast<pointer>(nullptr), details::extent_type<0>())
{
}

// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
// on Container to be a contiguous sequence container.
Expand Down

0 comments on commit dd9716a

Please sign in to comment.