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而是,为什么它不是可移动的可构造的?