std::piecewise_construct
来自cppreference.com
工具库
std::pair
成员函数 | ||||
(C++11)
|
||||
非成员函数 | ||||
(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20
前)(C++20)
|
||||
(C++11)
|
||||
(C++11)
|
||||
推导指引(C++17) | ||||
辅助类 | ||||
(C++11)
|
||||
(C++11)
|
||||
(C++23)
|
||||
(C++23)
|
在标头
<utility>
定义
|
||
constexpr std::piecewise_construct_t
piecewise_construct{};
|
(C++11 起) (C++17 前) |
|
inline constexpr std::piecewise_construct_t
piecewise_construct{};
|
(C++17 起) | |
常量 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
参阅
(C++11)
|
用于为逐段构造选择正确函数重载的标签类型 (类) |
构造新的 pair ( std::pair<T1,T2>
的公开成员函数)
|