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 @@ -235,4 +235,16 @@ T& SpanPopBack(Span<T>& span)
235235 return back;
236236}
237237
238+ // Helper functions to safely cast to unsigned char pointers.
239+ inline unsigned char * UCharCast (char * c) { return (unsigned char *)c; }
240+ inline unsigned char * UCharCast (unsigned char * c) { return c; }
241+ inline const unsigned char * UCharCast (const char * c) { return (unsigned char *)c; }
242+ inline const unsigned char * UCharCast (const unsigned char * c) { return c; }
243+
244+ // Helper function to safely convert a Span to a Span<[const] unsigned char>.
245+ 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 ()}; }
246+
247+ /* * Like MakeSpan, but for (const) unsigned char member types only. Only works for (un)signed char containers. */
248+ template <typename V> constexpr auto MakeUCharSpan (V&& v) -> decltype(UCharSpanCast(MakeSpan(std::forward<V>(v)))) { return UCharSpanCast (MakeSpan (std::forward<V>(v))); }
249+
238250#endif
You can’t perform that action at this time.
0 commit comments