This is an example of using TList with STL algoritms in CLING.
Processing /mnt/build/workspace/root-makedoc-v608/rootspi/rdoc/src/v6-08-00-patches/tutorials/cont/TListAndSTL.C...
Value: test string #0
Value: test string #1
Value: test string #2
Value: test string #3
Value: test string #4
Value: test string #5
Value: test string #6
Value: test string #7
Value: test string #8
Value: test string #9
The string has been found: test string #4
#include <algorithm>
#include <iostream>
#include <sstream>
struct SEnumFunctor {
if (!aObj)
return false;
if (!str)
return false;
cout << "Value: " << str->String().Data() << endl;
return true;
}
};
struct SFind {
SFind(
const TString &aStr): fToFind(aStr) {
}
return !str->String().CompareTo(fToFind);
}
private:
};
void TListAndSTL()
{
ostringstream ss;
for (int i = 0; i < size; ++i) {
ss << "test string #" << i;
ss.str("");
}
for_each(stringList.
begin(), stringList.
end(), SEnumFunctor());
string strToFind("test string #4");
SFind
func(strToFind.c_str());
if (!(*found)) {
cerr << "Can't find the string: \"" << strToFind << "\" in the container" << endl;
return;
}
TObjString *str(dynamic_cast<TObjString*>(*found));
if (!str) {
cerr << "Can't find the string: \"" << strToFind << "\" in the container" << endl;
return;
}
cout << "The string has been found: " << str->String().Data() << endl;
}
- Author
- Anar Manafov
Definition in file TListAndSTL.C.