3

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.

2
  • 3
    Someone is going to have to iterate over that vector, creating strings from the string_view. Commented Sep 14, 2019 at 18:19
  • You can't accomplish this without iteration. But if you don't want to iterate manually, then use an algorithm like std::for_each() or std::transform() Commented Sep 14, 2019 at 19:13

1 Answer 1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah. This is what I was looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.