An one liner to unpack QRegularExpressionMatch results into multiple variable?
-
I have a
QRegularExpression
object that captures multiple groups from strings, and aQRegularExpressionMatch::capture(n)
to split them out individually.Is there an one liner like in python where I can unpack them all at once like this instead of one at a time?
[id, name, type, text] = infoREMatch.capture();
-
@lansing said in An one liner to unpack QRegularExpressionMatch results into multiple variable?:
Is there an one liner like in python where I can unpack them all at once
No, there is not
-
@lansing said in An one liner to unpack QRegularExpressionMatch results into multiple variable?:
But still it couldn't be unpack.
? In C++ it's like a one-line function wrapper. Yes, C++ isn't the same as Python. Thank goodness! Use Python + PySide2/PyQt5 if you prefer what you can do there over C++.
-
You could write a wrapper that returns tuples and use tie to place in separate vars:
https://www.geeksforgeeks.org/how-to-return-multiple-values-from-a-function-in-c-or-cpp/
Scroll to the tuple example. Yes Python has some nice things. I would really love comprehensions in C++.