Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::piecewise_construct(3)   C++ Standard Libary  std::piecewise_construct(3)

NAME
       std::piecewise_construct	- std::piecewise_construct

Synopsis
	  Defined in header <utility>
	  struct  piecewise_construct_t	 {  explicit piecewise_construct_t() =
       (since C++11)
	  default; };
	  constexpr	std::piecewise_construct_t	piecewise_construct{};
       (since C++11)
										 (un-
       til C++17)
	  inline  constexpr  std::piecewise_construct_t	piecewise_construct{};
       (since C++17)

	  std::piecewise_construct_t is	an empty class tag type	used to	disam-
       biguate between
	  different functions that take	two tuple arguments. The constant
	  std::piecewise_construct is an instance of it.

	  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 el-
       ement of	the
	  pair.

Example
       // Run this code

	#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:
	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

	 Defect	reports

	  The following	behavior-changing defect reports were applied retroac-
       tively to
	  previously published C++ standards.

	     DR	      Applied	 to		    Behavior	as   published
       Correct behavior
	  LWG 2510 C++11      the default constructor was non-explicit,	 which
       made explicit
			      could lead to ambiguity

See also
	  constructor	constructs new pair
			(public	member function	of std::pair<T1,T2>)

http://cppreference.com		  2022.07.31	   std::piecewise_construct(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::piecewise_construct&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help