Reason for returning an rvalue reference

Viewed 115

I see a class defined like the following:

class Foo {
 public:
  template <typename T, typename... Args>
  Foo&& addElement(Args&&... args) {       <--- why do we return Foo&&
    elements_.emplace_back(
      std::make_unique<T>(std::forward<Args>(args)...));
    return std::move(*this);
  }

 private:
  std::vector<std::unique_ptr<Bar>> elements_;
};

I can't think of any good reasons for the returning type of function addElement(). Does it make sense to return an rvalue reference, or it is not a good idea? If so, what is the potential reason for doing that?

0 Answers
Related