Hacker News new | ask | show | jobs
by phoe-krk 2209 days 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;
    }
1 comments

Yes, 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.