File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -207,4 +207,16 @@ T& SpanPopBack(Span<T>& span)
207207 return back;
208208}
209209
210+ // Helper functions to safely cast to unsigned char pointers.
211+ inline unsigned char * UCharCast (char * c) { return (unsigned char *)c; }
212+ inline unsigned char * UCharCast (unsigned char * c) { return c; }
213+ inline const unsigned char * UCharCast (const char * c) { return (unsigned char *)c; }
214+ inline const unsigned char * UCharCast (const unsigned char * c) { return c; }
215+
216+ // Helper function to safely convert a Span to a Span<[const] unsigned char>.
217+ template <typename T> constexpr auto UCharSpanCast (Span<T> s) -> Span<typename std::remove_pointer<decltype(UCharCast(s.data()))>::type> { return {UCharCast (s.data ()), s.size ()}; }
218+
219+ /* * Like MakeSpan, but for (const) unsigned char member types only. Only works for (un)signed char containers. */
220+ template <typename V> constexpr auto MakeUCharSpan (V&& v) -> decltype(UCharSpanCast(MakeSpan(std::forward<V>(v)))) { return UCharSpanCast (MakeSpan (std::forward<V>(v))); }
221+
210222#endif
You can’t perform that action at this time.
0 commit comments