Chapter 39. Monoliths “Unstrung,” Part 3: std::string Diminishing

Difficulty: 5

The Slim-Fast diet continues, and std::string is indeed slimming fast.

Solution

More Operations That Can Be Nonmember Nonfriends

In this Item, we'll see that all the following functions can be implemented as non-member nonfriends:

  • resize (2)

  • assign (6)

  • += (3)

  • append (6)

  • push_back

  • insert (7—all but the three-parameter version)

Let's investigate.

resize

  1. Can string::resize be a nonmember function? Explain.

Well, let's ...

Get Exceptional C++ Style 40 New Engineering Puzzles, Programming Problems, and Solutions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.