本文整理汇总了C++中ContainerType::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ ContainerType::reserve方法的具体用法?C++ ContainerType::reserve怎么用?C++ ContainerType::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerType
的用法示例。
在下文中一共展示了ContainerType::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Precondition
MSSpectrum &MSSpectrum::select(const std::vector<Size> &indices)
{
Size snew = indices.size();
ContainerType tmp;
tmp.reserve(indices.size());
const Size peaks_old = size();
for (Size i = 0; i < snew; ++i)
{
tmp.push_back(*(ContainerType::begin() + indices[i]));
}
ContainerType::swap(tmp);
for (Size i = 0; i < float_data_arrays_.size(); ++i)
{
if (float_data_arrays_[i].size() != peaks_old)
{
throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FloatDataArray[" + String(i) + "] size (" +
String(float_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
}
std::vector<float> mda_tmp;
mda_tmp.reserve(float_data_arrays_[i].size());
for (Size j = 0; j < snew; ++j)
{
mda_tmp.push_back(*(float_data_arrays_[i].begin() + indices[j]));
}
std::swap(float_data_arrays_[i], mda_tmp);
}
for (Size i = 0; i < string_data_arrays_.size(); ++i)
{
if (string_data_arrays_[i].size() != peaks_old)
{
throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "StringDataArray[" + String(i) + "] size (" +
String(string_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
}
std::vector<String> mda_tmp;
mda_tmp.reserve(string_data_arrays_[i].size());
for (Size j = 0; j < snew; ++j)
{
mda_tmp.push_back(*(string_data_arrays_[i].begin() + indices[j]));
}
std::swap(string_data_arrays_[i], mda_tmp);
}
for (Size i = 0; i < integer_data_arrays_.size(); ++i)
{
if (integer_data_arrays_[i].size() != peaks_old)
{
throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "IntegerDataArray[" + String(i) + "] size (" +
String(integer_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
}
std::vector<Int> mda_tmp;
mda_tmp.reserve(integer_data_arrays_[i].size());
for (Size j = 0; j < snew; ++j)
{
mda_tmp.push_back(*(integer_data_arrays_[i].begin() + indices[j]));
}
std::swap(integer_data_arrays_[i], mda_tmp);
}
return *this;
}