CS253: Software Development with C++

Fall 2019

IQ 14

CS253 IQ 14

Show Main.IQ14 as a slide show.

Initializer Lists

Which of these is not a method of std::initializer_list?

  1. .begin()
  2. .end()
  3. .size()
  4. .empty()
  5. 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

const regex r("Crown*Vic");
if (regex_search("Crown Princess Victoria", r))
    cout << "Hooray!\n";
else
    cout << "Bummer!\n";
Bummer!
Crown Princess Victoria marries Daniel Westling

What will this code produce?

  1. Hooray!
  2. Bummer!
  3. 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

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?

  1. Hooray!
  2. Bummer!
  3. It will not compile.

“any number” includes zero.

Regular Expressions

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?

  1. Hooray!
  2. Bummer!
  3. It will not compile.

Regular Expressions

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?

  1. Hooray!
  2. Bummer!
  3. It will not compile.