Std::string to std::array?

c++, c++11

Solution

That seems fine. There isn't such a thing in C++11, and I don't think there is one in Boost either. If you don't want to paste this all over the place, you can just put it in a header and `#include` that.

Problem

What's the recommended way to convert a string to an array? I'm looking for something like: ``` template<class T, size_t N, class V> std::array<T, N> to_array(const V& v) { assert(v.size() == N); std::array<T, N> d; std::copy(v.begin(), v.end(), d.data()); return d; } ``` Does C++11 or Boost provide something like this? How do others do this? Seems silly having to copy/paste this function myself every time I need it in a project.

Original source