I have operator[] for my class, and all it does is call std::unique_ptr::operator[] on the unique_ptr member. The relevant part is precisely this:
template <typename T> struct Foo { T& operator [](const size_t pos) const noexcept { return data_[pos]; } std::unique_ptr<T[]> data_; };
I marked the operator as noexcept . However, unique_ptr::operator[] not noexcept . I canβt understand why this is so, and can I just assume that he will never quit. unique_ptr::operator[] itself does not list any exceptions in the documentation (cppreference and MSDN claim that it does not define a list of exceptions that it can throw.)
So, I assume that the missing noexcept may be: a) an error, or b) the underlying data type that the operator can access. Option a would be nice, as that would mean that I can mark my own noexcept . Option b will be hard to understand, since the whole operator gets the link and says nothing.
So, a long story, is it possible for unique_ptr::operator[] to ever be thrown, and is it safe to call from the noexcept function?
source share