std::piecewise_construct - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::piecewise_construct

From cppreference.com
< cpp‎ | utility

constexpr piecewise_construct_t piecewise_construct = std::piecewise_construct_t(); |  | (since C++11)

The constant std::piecewise_construct is an instance of an empty struct tag type std::piecewise_construct_t.

### [edit] Example

[edit]
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

### [edit] See also

piecewise_construct_t (C++11) | tag type used to select correct function overload for piecewise construction (class) [edit]
(constructor) | constructs new pair (public member function of `std::pair`)

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/piecewise_construct&oldid=63515"