Creating a DimnameList from an std::vector<std::string> in C++

How can I create a DimnameList from a vector of strings in C++?

I am trying something like:

torch::DimnameList cpp_torch_dimname_list (std::vector<std::string> x) {
 
 std::vector<torch::Dimname> out;
 
 for (int i = 0; i < x.size(); ++i) {
   out.push_back(torch::Dimname::fromSymbol(torch::Symbol::dimname(x[i])));
 }
 
return out;
}

But this is not working as expected…