I'm trying to return a std::tuple
containing an element that is a non-copy-constructable type. This seems to prevent me from using the default class constructor to construct the tuple. For example, to return a tuple containing Foo
, a foo
instance must be created and std::move
d:
class Foo {
public:
Foo(const Foo&) = delete;
Foo(Foo&&) = default;
int x;
};
tuple<int, Foo> MakeFoo() {
Foo foo{37};
// return {42, {37}}; // error: could not convert ‘{42, {37}}’ from ‘’ to ‘std::tuple’
return {42, std::move(foo)};
}
On the other hand, if the class is defined to have a copy constructor, construction of the tuple works fine:
class Bar {
public:
Bar(const Bar&) = default;
int x;
};
tuple<int, Bar> MakeBar() {
return {42, {37}}; // compiles ok
}
Is there a way to use the MakeBar
syntax with the Foo
class?
return {42, Foo{37}};
?