summaryrefslogtreecommitdiff
path: root/include/mbgl/util/traits.hpp
blob: e37144e60e29c9c62f6416424c50650e958e338b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include <array>
#include <cstdint>
#include <type_traits>
#include <vector>

namespace mbgl {

template<typename T>
constexpr auto underlying_type(T t) -> typename std::underlying_type_t<T> {
    return typename std::underlying_type_t<T>(t);
}

template <typename T> struct is_utf16char_like: std::false_type {};
template <typename T> struct is_utf16char_like<const T>: is_utf16char_like<T> {};
template <> struct is_utf16char_like<char16_t>: std::true_type {};
template <> struct is_utf16char_like<wchar_t>: std::true_type {};
template <> struct is_utf16char_like<uint16_t>: std::true_type {};

template <typename T> using is_utf16char_like_pointer = std::integral_constant<bool, std::is_pointer<T>::value
                                                                                     && is_utf16char_like<typename std::remove_pointer<T>::type>::value>;

template <class OutPointer, class InChar>
typename std::enable_if<is_utf16char_like<InChar>::value && is_utf16char_like_pointer<OutPointer>::value, OutPointer>::type utf16char_cast(InChar *in)
{
    return reinterpret_cast<OutPointer>(in);
}

template <typename T>
struct is_linear_container : std::false_type {};

template <typename T, std::size_t N>
struct is_linear_container<std::array<T, N>> : std::true_type {};
template <typename... Ts>
struct is_linear_container<std::vector<Ts...>> : std::true_type {};

} // namespace mbgl