Skip to content

Instantly share code, notes, and snippets.

@pasbi
Last active January 13, 2022 19:44
Show Gist options
  • Save pasbi/0b2b1d54566f88e19adc3f00ed9b70b9 to your computer and use it in GitHub Desktop.
Save pasbi/0b2b1d54566f88e19adc3f00ed9b70b9 to your computer and use it in GitHub Desktop.
template<std::size_t N>
std::vector<char*> string_array_to_charpp(std::array<std::string, N>& string_array)
{
std::vector<char*> vs;
vs.reserve(N);
for (std::size_t i = 0; i < N; ++i) {
vs.push_back(string_array.at(i).data());
}
return vs;
}
void main()
{
// auto args = std::experimental::make_array<std::string>("test", "and", "other", "args");
// I didn't find a way to infer N without using std::experimental.
std::array<std::string, 4> args{"test", "and", "other", "args"};
auto argv = string_array_to_charpp(args);
QApplication app(args.size(), argv.data());
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment