4 ms·
C++17 is capable of multiple variable declaration, which is a similar concept. #include <tuple> #include <iostream> std::tuple<int, int> divid
by phoe-krk 6y ago
C++17 is capable of multiple variable declaration, which is a similar concept.
#include <tuple>
#include <iostream>
std::tuple<int, int> divide(int dividend, int divisor) {
return {dividend / divisor, dividend % divisor};
}
int main() {
using namespace std;
auto [quotient, remainder] = divide(14, 3);
cout << quotient << ',' << remainder << endl;
}
- amelius 6y agoYes, the code auto [quotient, remainder] = divide(14, 3); is not an assignment. In an assignment, you should write something like std::tie(quotient, remainder) = divide(14, 3); which is a tuple assignment written as a single assignment. This shows the kind of (imho) "ugly hacks" the C++ committee had to make to cover up the historical mistake with the comma operator.