Slide 36
Slide 36 text
STL Algorithms in Action
another for_each example
simultaneous validate/search test
void any_of_headers_full() {
{
vector h1 = { "Foo: bar", "Content-type: application/json", "X-SuperPower: toestrength",
"Accept: text/html,text/json,application/json" };
const HeaderData& hd = header_parse(h1, "X-SuperPower", "toestrength");
cout << "headers parse: " << hd << ", good " << hd.good_headers << ", bad " << hd.bad_headers;
for_each(hd.found_headers.begin(), hd.found_headers.end(), [](const auto& val) {
cout << "\n\t'" << val.first << "', '" << val.second << "'";
});
cout << endl;
}
{
vector h2 = { "Foo: bar", "Content-type: application/json", "X-SuperPower: supersmell", "Accept: text/ht
ml,text/json,application/json" };
const HeaderData& hd = header_parse(h2, "X-SuperPower", "toestrength");
cout << "headers parse: " << hd << ", good " << hd.good_headers << ", bad " << hd.bad_headers;
for_each(hd.found_headers.begin(), hd.found_headers.end(), [](const auto& val) {
cout << "\n\t'" << val.first << "', '" << val.second << "'";
});
cout << endl;
}
{
vector h3 = { "Foo : bar", "Content-type: application/json", "X-Superpower: toestrength", "Accept: text/
html,text/json,application/json" };
const HeaderData& hd = header_parse(h3, "X-SuperPower", "toestrength");
cout << "headers parse: " << hd << ", good " << hd.good_headers << ", bad " << hd.bad_headers;
for_each(hd.found_headers.begin(), hd.found_headers.end(), [](const auto& val) {
cout << "\n\t'" << val.first << "', '" << val.second << "'";
});
cout << endl;
}
}
Michael VanLoon - http://codeache.net - CPPcon 2015 36