Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is vector considered nothrow_move_constructible?

Tags:

c++

c++11

The specification for vector's move constructor is (copied out of the standard):

vector(vector&&);

Notice the lack of noexcept. But both gcc 4.8 and Clang 3.2 report that std::is_nothrow_move_constructible<std::vector<int>>::value returns true (i.e, 1):

#include<vector>
#include<iostream>

int main()
{
  std::cout << std::is_nothrow_move_constructible<std::vector<int>>::value << '\n';
}

What is the cause of this apparent discrepancy?

like image 749
KnowItAllWannabe Avatar asked Nov 14 '13 20:11

KnowItAllWannabe


Video Answer


1 Answers

The standard allows an implementation to strengthen the exception specification of a method as per

17.6.5.12 Restrictions on exception handling [res.on.exception.handling]

4 Destructor operations defined in the C++ standard library shall not throw exceptions. Every destructor in the C++ standard library shall behave as if it had a non-throwing exception specification. Any other functions defined in the C++ standard library that do not have an exception-specification may throw implementation-defined exceptions unless otherwise specified.191 An implementation may strengthen this implicit exception-specification by adding an explicit one.192

like image 66
Daniel Frey Avatar answered Sep 28 '22 05:09

Daniel Frey