本文整理汇总了C++中Bag::IsPresent方法的典型用法代码示例。如果您正苦于以下问题:C++ Bag::IsPresent方法的具体用法?C++ Bag::IsPresent怎么用?C++ Bag::IsPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bag
的用法示例。
在下文中一共展示了Bag::IsPresent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
//test creation of multiple types
Bag<int> IntBag;
Bag<double> DoubleBag;
Bag<string> StringBag;
bool passed;
for (int j = 0; j < 50000; j++) {
IntBag.AddItem(j);
passed = true;
}
for (int j = 0; j < 50000; j++){
if (!IntBag.IsPresent(j)){
cout << "Error: Lost item " << j << endl;
passed = false;
}
}
if (passed) {
cout << "Retained all items \n";
}
else
cout << "Failed test\n";
passed = true;
for (int j = 50000; j < 50050; j++){
if (IntBag.IsPresent(j) || IntBag.IsPresent(j*-1)){
passed = false;
cout << "Found extra item: " << j << '\n';
}
}
if (passed) {
cout << "No extra items \n";
}
else
cout << "Failed extra-item test\n";
passed = false;
try{
IntBag.Discard(-1);
}
catch (BagException){
passed = true;
cout << "Raised expected exception on discarding nonexistent item\n";
}
if (passed) {
cout << "Handled discard of non-existent item \n";
}
else
cout << "Failed discard test\n";
IntBag.Discard(12);
if (IntBag.IsPresent(12)) {
cout << "Failed to discard item\n";
}
else
cout << "Discard-item test passed.\n";
IntBag.Clear();
if (!IntBag.IsEmpty()) {
cout << "Failed to clear Bag\n";
}
else
cout << "Cleared Bag OK. \n";
if (IntBag.IsEmpty() && IntBag.Size() != 0) {
cout << "Error: Reports empty but nonzero count.\n";
}
system("pause");
return 0;
}