It’s often interesting to see just how much can be accomplished with just one line of code; this mini-article has been written to demonstrate a solution to an age-old problem: How to convert *argv[] into something usable in (Modern) C++.
Any seasoned C programmer will be quick to tell you there are two forms to the main() function, the empty parentheses variant and the one specifying argc (number of arguments) and argv (a pointer to an array of pointer to char).
If your head hurts if you try to determine whether there’s any difference to declaring argv as const char **argv or const char *argv[] you’re probably not alone. (No, there isn’t a difference, is the answer.) In Modern C++ we hardly want to be messing around with a single const char * if we can help it, never mind an array of them. So, how to construct and populate a vector of string views in one line? Here is the code (line 12 is the one-line magic):