MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / tryAllocVector

Function tryAllocVector

quest/src/core/utilities.cpp:1179–1195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1177
1178template <typename T>
1179void 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
1197void util_tryAllocVector(vector<qreal> &vec, qindex size, std::function<void()> errFunc) { tryAllocVector(vec, size, errFunc); }
1198void util_tryAllocVector(vector<qcomp> &vec, qindex size, std::function<void()> errFunc) { tryAllocVector(vec, size, errFunc); }

Callers 1

util_tryAllocVectorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected