50. Filtering a list of phone numbers

The solution to this problem is relatively simple: you have to iterate through all the phone numbers and copy to a separate container (such as an std::vector) the phone numbers that start with the country code. If the specified country code is, for instance, 44, then you must check for both 44 and +44. Filtering the input range in this manner is possible using the std::copy_if() function. A solution to this problem is shown here:

bool starts_with(std::string_view str, std::string_view prefix){   return str.find(prefix) == 0;}template <typename InputIt>std::vector<std::string> filter_numbers(InputIt begin, InputIt end,                                        std::string const & countryCode){   std::vector<std::string> result;   std::copy_if( begin, ...

Get The Modern C++ Challenge 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.