| 1177 | |
| 1178 | template <typename T> |
| 1179 | void tryAllocVector(vector<T> &vec, qindex size, std::function<void()> errFunc) { |
| 1180 | |
| 1181 | // this function resizes the vector, not only reserving it, |
| 1182 | // such that vec.size() will subsequently return 'size' |
| 1183 | |
| 1184 | if (size == 0) |
| 1185 | return; |
| 1186 | |
| 1187 | try { |
| 1188 | vec.resize(size); |
| 1189 | |
| 1190 | } catch (std::bad_alloc &e) { |
| 1191 | errFunc(); |
| 1192 | } catch (std::length_error &e) { |
| 1193 | errFunc(); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | void util_tryAllocVector(vector<qreal> &vec, qindex size, std::function<void()> errFunc) { tryAllocVector(vec, size, errFunc); } |
| 1198 | void util_tryAllocVector(vector<qcomp> &vec, qindex size, std::function<void()> errFunc) { tryAllocVector(vec, size, errFunc); } |
no outgoing calls
no test coverage detected