constant
<utility>
std::piecewise_construct
constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
Piecewise construct constant
This constant value is passed as the first argument to construct a pair object to select the constructor form that constructs its members in place by forwarding the elements of two tuple objects to their respective constructor.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// piecewise_construct example
#include <utility> // std::pair, std::piecewise_construct
#include <iostream> // std::cout
#include <tuple> // std::forward_as_tuple
#include <vector> // std::vector
#include <string> // std::string
int main () {
std::pair < std::string, std::vector<int> >
foo (
std::piecewise_construct,
std::forward_as_tuple("test"),
std::forward_as_tuple(3,10)
);
std::cout << "foo.first: " << foo.first << '\n';
std::cout << "foo.second:";
for (int& x: foo.second) std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
|
Output:
foo.first: test
foo.second: 10 10 10
|
See also
- pair::pair
- Construct pair (public member function)