mercredi 25 octobre 2017

Cannot initialize const int from unpacked tuple

Question is really simple, why is this code not working:

#include <tuple>

int main( int argc, char* argv[]) {
    const int a,b = std::tie(std::make_pair(1,2));
    return EXIT_SUCCESS;
}

g++ gives me this error:

./test.cpp: In function ‘int main(int, char**)’: ./test.cpp:4:13: error: uninitialized const ‘a’ [-fpermissive] const int a,b = std::tie(std::make_pair(1,2)); ^ ./test.cpp:4:42:

error: cannot bind non-const lvalue reference of type ‘std::pair&’ to an rvalue of type ‘std::pair’
const int a,b = std::tie(std::make_pair(1,2));

I cannot get any tuple-like return by value, using this kind of pattern (either const or non const). Is it a better way to do what I am trying to achieve here ?

Aucun commentaire:

Enregistrer un commentaire