CS253 IQ 14
Show Main.IQ14 as a slide show.
Initializer Lists
Which of these is not a method of std::initializer_list
?
.begin()
.end()
.size()
.empty()
- They are all methods of
std::initializer_list
.
An initializer_list
can never be empty, so .empty()
doesn’t exist.
It would exist, for the sake of regularity, if I had my druthers.
Regular Expressions #1
const regex r("Crown*Vic");
if (regex_search("Crown Princess Victoria", r))
cout << "Hooray!\n";
else
cout << "Bummer!\n";
Bummer!
What will this code produce?
Hooray!
Bummer!
- It will not compile.
This is a regular expression, not a filename pattern, so *
is a multiplier—any number of what came before.
Regular Expressions #2
const regex r("C*P*Vic");
if (regex_search("Crown Princess Victoria", r))
cout << "Hooray!\n";
else
cout << "Bummer!\n";
Hooray!
What will this code produce?
Hooray!
Bummer!
- It will not compile.
“any number” includes zero.
Regular Expressions #3
const regex r("C.*P.*Vic");
if (regex_search("Crown Princess Victoria", r))
cout << "Hooray!\n";
else
cout << "Bummer!\n";
Hooray!
What will this code produce?
Hooray!
Bummer!
- It will not compile.
Regular Expressions #4
const regex r(R"(C.*\w+\sVic)");
if (regex_search("Crown Princess Victoria", r))
cout << "Hooray!\n";
else
cout << "Bummer!\n";
Hooray!
What will this code produce?
Hooray!
Bummer!
- It will not compile.