A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/utility/piecewise_construct/ below:

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)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4