Ilyas H
Ilyas H

Reputation: 337

How to create a vector of strings from a vector of string_view without iteration?

I have the following vector:

std::vector<std::string_view> const keys{"A1", "A2", "A3", "B1", "C1"};

I want to create a vector of std::string out of it without iterating over it.

Upvotes: 3

Views: 4098

Answers (1)

Igor Tandetnik
Igor Tandetnik

Reputation: 52611

std::vector<std::string> v(keys.begin(), keys.end());

should do it. Of course, there's iteration hidden inside that constructor.

Upvotes: 5

Related Questions