47 //! \brief count the amount of elements in a basic array |
48 //! \brief count the amount of elements in a basic array |
48 template<typename T, int N> |
49 template<typename T, int N> |
49 constexpr int countof(T(&)[N]) |
50 constexpr int countof(T(&)[N]) |
50 { |
51 { |
51 return N; |
52 return N; |
52 } |
|
53 |
|
54 //! \brief casts @c x to a suitable unsigned integer |
|
55 template<typename T> |
|
56 constexpr auto unsigned_cast(T x) |
|
57 -> std::enable_if_t<std::is_integral_v<T>, std::make_unsigned_t<T>> |
|
58 { |
|
59 return static_cast<std::make_unsigned_t<T>>(x); |
|
60 } |
|
61 |
|
62 //! \brief casts @c x to a suitable signed integer |
|
63 template<typename T> |
|
64 constexpr auto signed_cast(T x) |
|
65 -> std::enable_if_t<std::is_integral_v<T>, std::make_signed_t<T>> |
|
66 { |
|
67 return static_cast<std::make_signed_t<T>>(x); |
|
68 } |
|
69 |
|
70 //! \brief casts floating point values to float |
|
71 template<typename T> |
|
72 constexpr auto float_cast(T x) |
|
73 -> std::enable_if_t<std::is_floating_point_v<T>, float> |
|
74 { |
|
75 return static_cast<float>(x); |
|
76 } |
|
77 |
|
78 //! \brief casts floating point values to double |
|
79 template<typename T> |
|
80 constexpr auto double_cast(T x) |
|
81 -> std::enable_if_t<std::is_floating_point_v<T>, double> |
|
82 { |
|
83 return static_cast<double>(x); |
|
84 } |
|
85 |
|
86 //! \brief casts floating point values to qreal |
|
87 template<typename T> |
|
88 constexpr auto qreal_cast(T x) |
|
89 -> std::enable_if_t<std::is_floating_point_v<T>, qreal> |
|
90 { |
|
91 return static_cast<qreal>(x); |
|
92 } |
53 } |
93 |
54 |
94 template<int N, typename T, glm::qualifier Q> |
55 template<int N, typename T, glm::qualifier Q> |
95 constexpr QPointF toQPointF(const glm::vec<N, T, Q>& vec) |
56 constexpr QPointF toQPointF(const glm::vec<N, T, Q>& vec) |
96 { |
57 { |