@@ -25,6 +25,23 @@ class Span
25
25
constexpr Span (C* data, std::ptrdiff_t size) noexcept : m_data(data), m_size(size) {}
26
26
constexpr Span (C* data, C* end) noexcept : m_data(data), m_size(end - data) {}
27
27
28
+ /* * Implicit conversion of spans between compatible types.
29
+ *
30
+ * Specifically, if a pointer to an array of type O can be implicitly converted to a pointer to an array of type
31
+ * C, then permit implicit conversion of Span<O> to Span<C>. This matches the behavior of the corresponding
32
+ * C++20 std::span constructor.
33
+ *
34
+ * For example this means that a Span<T> can be converted into a Span<const T>.
35
+ */
36
+ template <typename O, typename std::enable_if<std::is_convertible<O (*)[], C (*)[]>::value, int >::type = 0 >
37
+ constexpr Span (const Span<O>& other) noexcept : m_data(other.m_data), m_size(other.m_size) {}
38
+
39
+ /* * Default copy constructor. */
40
+ constexpr Span (const Span&) noexcept = default;
41
+
42
+ /* * Default assignment operator. */
43
+ Span& operator =(const Span& other) noexcept = default ;
44
+
28
45
constexpr C* data () const noexcept { return m_data; }
29
46
constexpr C* begin () const noexcept { return m_data; }
30
47
constexpr C* end () const noexcept { return m_data + m_size; }
@@ -44,6 +61,8 @@ class Span
44
61
friend constexpr bool operator <=(const Span& a, const Span& b) noexcept { return !(b < a); }
45
62
friend constexpr bool operator >(const Span& a, const Span& b) noexcept { return (b < a); }
46
63
friend constexpr bool operator >=(const Span& a, const Span& b) noexcept { return !(a < b); }
64
+
65
+ template <typename O> friend class Span ;
47
66
};
48
67
49
68
/* * Create a span to a container exposing data() and size().
0 commit comments