Consider this. There is a non-copyable, non-movable class, and there is some predicated defined for it:
struct AA
{
AA(AA const& otehr) = delete;
AA(AA && otehr) = delete;
AA& operator = (AA const& otehr) = delete;
AA& operator = (AA && otehr) = delete;
AA(int something) { }
bool good() const { return false; }
};
Because of guaranteed copy/move-elision in C++17 we can have:
auto getA() { return AA(10); }
The question is: how can one define getGoodA
, that will forward getA
in case it returned good
and will throw an exception otherwise? Is it possible at all?
auto getGoodA()
{
auto got = getA();
if (got.good()) return got; // FAILS! Move is needed.
throw std::runtime_error("BAD");
}