为什么std :: pair不能不构造?

Nic*_*ick 5 c++ constructor move-semantics nothrow

以下代码:

#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
using namespace std;

struct Foo
{
    std::string s;
    int i;
};

int main()
{
    cout << boolalpha << is_nothrow_constructible<Foo>::value << endl;
    cout << is_nothrow_constructible<pair<string, int>>::value << endl;

    cout << is_nothrow_move_constructible<Foo>::value << endl;
    cout << is_nothrow_move_constructible<pair<string, int>>::value << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译时产生以下输出g++ -std=c++11:

true
false
true
true
Run Code Online (Sandbox Code Playgroud)

为什么std::pair<string, int>不是建设性的,Foo而是,为什么它不是可移动的可构造的?

bip*_*pll 3

有趣的是,在任何情况下都没有将任何构造函数声明为 noexcept。可能是典型的标准缺陷(只有下面的文字描述承诺如果没有任何元素抛出任何异常,则不会抛出任何异常。)