std::tuple
は高度にテンプレートを搭載した獣です。 n番目のメンバコンパイラにアクセスするには、テンプレートインスタンスを十分に実行する必要がありますが、その単純な性質は、対応する仮想構造体のn番目のデータメンバにアクセスすることです。このような何か(擬似コード)、std::tuple
は、コア言語の機能であることを思わ:バリアント集合体はコア言語機能として
template< typename ...types >
struct/* or class, or even union */ V
{
types... V; // defines implicitly `operator [/*constant expression*/]` to access by index
// if more than one variadic parameter pack provided
// (during expanding of parameter pack of template
// parameters in specializations) then instead of
// `V` there can be specific data-member name (say, `x`),
// but still with `x.operator []` implicitly defined
// member functions and data members allowed
};
template< typename ...types >
V< std::decay_t<types>... > make_tuple(types &&... args)
{ return {std::forward<types>(args)...}; }
template< typename ...types >
V< types &&... > forward_as_tuple(types &&... args)
{ return {std::forward<types>(args)...}; }
template< typename ...types >
V< types &... > tie(types &... args)
{ return {args...}; }
は、クラスのための可変長のデータ・メンバーの定義構文をサポートしている言語のようなものの任意の提案はありますか?
コア言語機能を使用する利点は何ですか?なぜ 'std :: tuple'だけなのでしょうか?なぜ 'std :: vector'でもないのですか?私の考えは、もし何かがライブラリの機能として行えるのであれば、*それができない(またはあまりにもハッキリしている)場合にのみ、言語機能を追加するのが理にかなっています。 – Nawaz
言語で既に存在する@Nawaz POD配列(単一の型、複数の値)、 'int x [3] = {1、2、3};'。 – Orient
'types ... V;'、 'operator [](size_t)'には関係なく、存在することはできません。 – Barry