mardi 31 janvier 2017

Noexcept for classes that use a stringstream

I have a class that has a std::stringstream member:

class Buffer
{
    std::stringstream ss_;
};

Its move constructor is

Buffer::Buffer(Buffer&& buf)
: ss_(std::move(buf.ss_))
{
}

I suspect that the move operation will not throw and the move constructor could be noexcept because of this. So my questions are:

  1. How do I determine if a function from the STL is declared noexcept, for example std::stringstream::str?
  2. If swapping or moving the stringstream was not noexcept, could I still declare the Buffer members noexcept and get a call to std::unexpected() if an exception is thrown by the stringstream? From what I can find that would be the case.
  3. Is there a way around the problem, for example an alternate container that can be written to using the stream operators and that is noexcept?

Aucun commentaire:

Enregistrer un commentaire