jeudi 26 août 2021

Return std::tuple containing const-reference in C++11

I have something like this (C++11)

std::tuple<const MyType&, bool>> func()
{
   return std::make_tuple(some_internal_reference, true);
}

the problem is that in the caller I cannot declare:

const MyType& obj; // this does not compile of course
bool b;

std::tie(obj, b) = func();

An idea is to return the boolean as an output param and drop the tuple, but is there a better solution?

Aucun commentaire:

Enregistrer un commentaire