Function moving std::vector exception safety

Viewed 26

For the following code snippet (using C++14 standard), can we declare setDataVectoras noexcept?

class Data {
public:
  using Type = ...; // A class with a default move assignment operator. Or even just uint32_t

  void setDataVector(std::vector<Type> &&input) // Can be declared as noexcept?
  {
    data = std::move(input);
  }

private:
  std::vector<Type> data;
};

In cppreference, it is mentioned that until C++17, the move assignment operator for std::vector is not noexcept.

vector& operator=( vector&& other );

Can it really throw even for trivial datatypes like integer?

What is confusing me is that move operations should be exception-safe but std::vector and std::string for example don't have a noexcept move assignment operators.

So, What am I missing here?

0 Answers
Related