I have a problem where if I use my class as the element type in a vector it doesn't move it but rather constructs it and tries to copy assign it (I believe because the compiler sees certain functions as throwing exceptions). I don't want to redefine my own move constructor every time this happens, can I default the move constructor but specify that it's noexcept?
struct QueueSubmission
{
QueueSubmission(VulkanFence is_completed_fence) : is_completed_fence(is_completed_fence)
{}
QueueSubmission(QueueSubmission&& other) noexcept = default;
QueueSubmission& operator=(QueueSubmission&& other) noexcept = default;
/* CommandBufferUniquePointer cannot be copied, but only moved */
std::vector<CommandBufferUniquePointer> command_buffers_submitted;
};
CodePudding user response:
Yes, if functions are defaulted on their first declaration without noexcept
specifier, then they will be noexcept(true)
if and only if they don't contain anything potentially throwing.
But if you add a noexcept
specifier this will override it.
Note my comments under your question though.