return tuple of uncopyable objects

Consider the following:

std::tuple<std::string, std::string> foo() {
  std::string a = "hello";

  return {a, a};
}

The fact that your usage of file and data in your specific expressions is implicitely safely movable does not mean that it's always the case, even for very similar expressions.

The compiler has to be CERTAIN that the named identifier is doomed in order to treat it as a r-value, and such an analysis would quickly become unreasonably complex.


There's no standard function, but this should work (C++17):

template <class... Types>
auto move_to_tuple(Types&&... args) {
    return std::make_tuple(std::move(args)...);
}

Tags:

C++