src/basics.h

changeset 53
3af627f7a40f
parent 51
1a9eac27698d
child 55
cb81ecb5fb23
equal deleted inserted replaced
52:eee644f88e93 53:3af627f7a40f
20 #include <algorithm> 20 #include <algorithm>
21 #include <cstdio> 21 #include <cstdio>
22 #include <cstdlib> 22 #include <cstdlib>
23 #include <cstring> 23 #include <cstring>
24 #include <cmath> 24 #include <cmath>
25 #include <optional>
25 #include <QMatrix4x4> 26 #include <QMatrix4x4>
26 #include <QObject> 27 #include <QObject>
27 #include <QPointF> 28 #include <QPointF>
28 #include <QSet> 29 #include <QSet>
29 #include <QString> 30 #include <QString>
103 -> std::enable_if_t<std::is_integral_v<T>, std::make_signed_t<T>> 104 -> std::enable_if_t<std::is_integral_v<T>, std::make_signed_t<T>>
104 { 105 {
105 return static_cast<std::make_signed_t<T>>(x); 106 return static_cast<std::make_signed_t<T>>(x);
106 } 107 }
107 108
109
110 /**
111 * @brief casts double and long double - and only those types - to float
112 * @param[in] x double or long double to cast
113 * @returns float
114 */
115 template<typename T>
116 auto doubleToFloat(T x)
117 -> std::enable_if_t<
118 std::is_same_v<std::decay_t<T>, double> ||
119 std::is_same_v<std::decay_t<T>, long double
120 >, float>
121 {
122 return static_cast<float>(x);
123 }
124
125 /**
126 * @brief Casts float - and only float - to double
127 * @param[in] x float to cast
128 * @returns double
129 */
130 template<typename T>
131 auto floatToDouble(T x)
132 -> std::enable_if_t<std::is_same_v<std::decay_t<T>, float>, double>
133 {
134 return static_cast<double>(x);
135 }
108 Q_DECLARE_METATYPE(glm::vec3) 136 Q_DECLARE_METATYPE(glm::vec3)
109 Q_DECLARE_METATYPE(glm::mat4) 137 Q_DECLARE_METATYPE(glm::mat4)

mercurial