Defined in header <utility> | ||||
---|---|---|---|---|
| (since 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.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #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); } |
Output:
1 2 3 4 | 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 |
See also
(C++11) | an object of type piecewise_construct_t used to disambiguate functions for piecewise construction (constant) |
constructs new pair (public member function of std::pair ) |
Please login to continue.