std::piecewise_construct_t
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <utility> 中定义
|
||
struct piecewise_construct_t { }; |
(C++11 起) | |
std::piecewise_construct_t is an empty struct tag type used to disambiguate between different functions that take two tuple arguments.
The overloads that do not use std::piecewise_construct_t assume that each tuple argument becomes the element of a pair. The overloads that use std::piecewise_construct_t assume that each tuple argument is used to construct, piecewise, a new object of specified type, which will become the element of the pair.
[编辑] 示例
#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) |
piecewise_construct_t 类型的对象使用,以消除歧义分段施工的功能 原文: an object of type piecewise_construct_t used to disambiguate functions for piecewise construction (常量) |