首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::piecewise_construct

constexpr piecewise_construct_t piecewise_construct = std::piecewise_construct_t();

(since C++11) (until C++17)

inline constexpr piecewise_construct_t piecewise_construct = std::piecewise_construct_t();

(since C++17)

常数std::piecewise_construct是空struct标记类型的实例。std::piecewise_construct_t...

二次

代码语言:javascript
复制
#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);
}

二次

产出:

二次

代码语言:javascript
复制
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

二次

另见

piecewise_construct_t (C++11)

tag type used to select correct function overload for piecewise construction (class)

(constructor)

constructs new pair (public member function of std::pair)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券