std::piecewise_construct_C++中文网
常量 std::piecewise_construct 是空的结构体标签类型 std::piecewise_construct_t 的一个实例。
示例
#include <iostream> #include <utility> #include <tuple> struct Foo { Foo(std::tuple<int, float>) { std::cout << "Constructed a Foo from a tuple\n"; } Foo(int, float) { std::cout << "Constructed a Foo from an int and a float\n"; } }; int main() { std::tuple<int, float> t(1, 3.14); std::pair<Foo, Foo> p1(t, t); std::pair<Foo, Foo> p2(std::piecewise_construct, t, t); }
输出:
Constructed a Foo from a tuple Constructed a Foo from a tuple Constructed a Foo from an int and a float Constructed a Foo from an int and a float