• Create Account

### #ActualServant of the Lord

Posted 26 February 2013 - 11:33 AM

I'm new to tuples, so this question is as much for my own education than as an answer to your question, but shouldn't that be std::make_tuple() not std::tie()?

Reading the documentation I just linked to, it says std::tie() makes a std::tuple of references. Once your std::array goes out of scope, wouldn't those references would be invalid?

Whereas std::make_tuple() copies the values, so the tuple owns it's own arrays.

To get rid of the copy, you could even use std::move():

return std::make_tuple(std::move(buff), std::move(buff2)); //I don't know if the std::move()s are done automatically be the compiler.


This is assuming that 'buff' and 'buff2' are never used again, like in your example.

If the two std::arrays continue to exist after the function ends, say, as member-variables of a class, then the std::tie() version that takes references would be valid as long as the class holding the real value is valid.

Am I missing something here?

### #2Servant of the Lord

Posted 26 February 2013 - 11:33 AM

I'm new to tuples, so this question is as much for my own education than as an answer to your question, but shouldn't that be std::make_tuple() not std::tie()?

Reading the documentation I just linked to, it says std::tie() makes a std::tuple of references. Once your std::array goes out of scope, wouldn't those references would be invalid?

Whereas std::make_tuple() copies the values, so the tuple owns it's own arrays.

To cut past the copy, you could even use std::move():

return std::make_tuple(std::move(buff), std::move(buff2)); //I don't know if the std::move()s are done automatically be the compiler.


This is assuming that 'buff' and 'buff2' are never used again, like in your example.

If the two std::arrays continue to exist after the function ends, say, as member-variables of a class, then the std::tie() version that takes references would be valid as long as the class holding the real value is valid.

Am I missing something here?

### #1Servant of the Lord

Posted 26 February 2013 - 11:30 AM

I'm new to tuples, so this question is as more for my own education than as an answer to your question, but shouldn't that be std::make_tuple() not std::tie()?

Reading the documentation I just linked to, it says std::tie() makes a std::tuple of references. Once your std::array goes out of scope, wouldn't those references would be invalid?

Whereas std::make_tuple() copies the values, so the tuple owns it's own arrays.

To cut past the copy, you could even use std::move():

return std::make_tuple(std::move(buff), std::move(buff2)); //I don't know if the std::move()s are done automatically be the compiler.


This is assuming that 'buff' and 'buff2' are never used again, like in your example.

If the two std::arrays continue to exist after the function ends, say, as member-variables of a class, then the std::tie() version that takes references would be valid as long as the class holding the real value is valid.

Am I missing something here?

PARTNERS