Suppose I have a "builder" class B
which builds a class C
, and looks somewhat like the following:
class B {public: // ... B& set_foo(Foo a_foo) { foo_ = std::move(a_foo); return *this; } C build() const { /* ... */ }};
This is all nice and good ... until I think about what happens when my B instance is a temporary. How should I design B
to work also as temporary/rvalue, not just as an lvalue?
- Should I write a
set_foo() &&
variant, returning aB&&
? That would mean replicating lots of methods, and well, DRY. - Should I just return
B&&
to begin with? - Should I do something else?