Skip to content

Commit cf4f3c5

Browse files
committed
span: Fixed a more const span not being constructable from a less
1 parent 7466e85 commit cf4f3c5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

substrate/span

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ namespace substrate
137137
constexpr span(type_t (&array)[N]) noexcept : span(static_cast<pointer>(array), N) { }
138138
template<typename type_t, size_t N, substrate::enable_if_t<isCompatArray<type_t, N>(), void *> = nullptr>
139139
constexpr span(std::array<type_t, N> &array) noexcept :
140-
span(static_cast<pointer>(array.data()), N) { }
140+
span{static_cast<pointer>(array.data()), N} { }
141141
template<typename type_t, size_t N, substrate::enable_if_t<isCompatArray<const type_t, N>(), void *> = nullptr>
142142
constexpr span(const std::array<type_t, N> &array) noexcept :
143-
span(static_cast<pointer>(array.data()), N) { }
143+
span{static_cast<pointer>(array.data()), N} { }
144+
145+
// Allow converting a less-const span into a more const one
146+
template<typename type_t, size_t N, substrate::enable_if_t<std::is_same_v<T, const type_t>, void *> = nullptr>
147+
constexpr span(const span<type_t, N> &other) noexcept : span{other.data(), other.size()} { }
144148

145149
template<class container_t, substrate::enable_if_t<extent_v == dynamic_extent &&
146150
internal::isContainer<container_t>(), void *> = nullptr>

0 commit comments

Comments
 (0)