名前空間
変種
操作

std::piecewise_construct_t

提供: cppreference.com
< cpp‎ | utility
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
std::pair
メンバ関数
非メンバ関数
(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20)
(C++11)
推定ガイド(C++17)
ヘルパークラス
(C++11)
 
ヘッダ <utility> で定義
struct piecewise_construct_t {};
(C++11以上)
(C++17未満)
struct piecewise_construct_t {explicit piecewise_construct_t()=default;};
(C++17以上)

std::piecewise_construct_t は2つのタプル引数を取る異なる関数間の曖昧性を解消するために使用される空の構造体タグ型です。

std::piecewise_construct_t を使用しないオーバーロードは、それぞれのタプル引数がペアの要素になると仮定します。 std::piecewise_construct_t を使用するオーバーロードは、それぞれのタプル引数は、ペアの要素となる指定された型の新しいオブジェクトを区分的に構築するために使用されます。

[編集]

#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);}

出力:

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 型のオブジェクト
(定数)[edit]
新しいペアを構築します
(std::pair<T1,T2>のパブリックメンバ関数)
close