共通の設計上の問題は、2つの変数をまとめて意味のある方法で参照することができなくなることです。std :: pairを使用できますが、.firstと.secondのメンバー名を変更できますか?
私が代わりに基本的な構造体を書い考えられてきましたが、その後、私はstd::pair
と一緒に来るの利益の多くを失う
std::pair<int,int> cords;
cord.first = 0; //is .first the x or y coordinate?
cord.second = 0; //is .second the x or y coordinate?
:
- make_pair
- 非会員オーバーロードされた演算子
- スワップ
- get
- など
first
およびsecond
データメンバの名前を変更するか、代わりの識別子を指定する方法はありますか?
私はstd::pair
受け入れるすべての機能を活用するために期待していた、
それでも、次の方法でそれらを使用することができる:あなたがこの問題を回避でき
std::pair<int,int> cords;
//special magic to get an alternative name of access for each data member.
//.first and .second each have an alternative name.
cords.x = 1;
assert(cords.x == cords.first);
を使用することができます。たぶん、std :: pairをラップするクラスを作るでしょうか? –
おそらく、定義されているタスクのためにおそらく過剰ですが、[BOOST_FUSION_DEFINE_STRUCT](http://www.boost.org/doc/libs/1_59_0/libs/fusion/doc/html/fusion/adapted/define_struct.html)では、比較演算子、スワップなどが自動的に生成される構造体ですが、カスタムフィールド名/型があります。 – Mankarse
'構造体コードについて:std :: pair {int&x = this-> first; int&y = this-> second; }; '? –
Slava