| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <type_traits> |
| 5 | |
| 6 | namespace mbgl { |
| 7 | |
| 8 | template<typename T> |
| 9 | constexpr auto underlying_type(T t) -> typename std::underlying_type_t<T> { |
| 10 | return typename std::underlying_type_t<T>(t); |
| 11 | } |
| 12 | |
| 13 | template <typename T> struct is_utf16char_like: std::false_type {}; |
| 14 | template <typename T> struct is_utf16char_like<const T>: is_utf16char_like<T> {}; |
| 15 | template <> struct is_utf16char_like<char16_t>: std::true_type {}; |
| 16 | template <> struct is_utf16char_like<wchar_t>: std::true_type {}; |
| 17 | template <> struct is_utf16char_like<uint16_t>: std::true_type {}; |
| 18 | |
| 19 | template <typename T> using is_utf16char_like_pointer = std::integral_constant<bool, std::is_pointer<T>::value |
| 20 | && is_utf16char_like<typename std::remove_pointer<T>::type>::value>; |
| 21 | |
| 22 | template <class OutPointer, class InChar> |
| 23 | typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_pointer<OutPointer>::value, OutPointer>::type utf16char_cast(InChar *in) |
| 24 | { |
| 25 | return reinterpret_cast<OutPointer>(in); |
| 26 | } |
| 27 | |
| 28 | } // namespace mbgl |
| 29 |
