2
は
私はこのようになりますいくつかのコードがあります。Boost :: tupleはPythonのitemgetterと同じですか?
typedef tuple<int, int, double> DataPoint;
vector<DataPoint> data;
vector<double> third_column_only;
// Code to read in data goes here.
transform(data.begin(), data.end(), back_inserter(values), tuples::get<1, DataPoint>);
を残念ながら、最後の行はコンパイルされません - それは私にこのようなメッセージ与えます:Pythonの演算子を使用するように、基本的に
/path/to/boost/tuple/detail/tuple_basic.hpp: In instantiation of `boost::tuples::cons': /path/to/boost/tuple/detail/tuple_basic.hpp:144: instantiated from `boost::tuples::element >' program.cc:33: instantiated from here /path/to/boost/tuple/detail/tuple_basic.hpp:329: error: `boost::tuples::cons::tail' has incomplete type /path/to/boost/tuple/detail/tuple_basic.hpp:329: error: invalid use of template type parameter /path/to/boost/tuple/detail/tuple_basic.hpp:151: confused by earlier errors, bailing out
を。 itemgetter関数のように、私は次のようにしたい:
transform(data.begin(), data.end(), back_inserter(values), itemgetter(2))
私はどのようにしてBoostを使ってそれを行うことができますか?
Thanks-boost :: bindはget <2、int、tupleのテンプレート宣言と同様に私が探していたものでした> - getのテンプレート宣言が代わりにを取得します。 しかし、bindを使用しても、get2のような関数宣言を追加しなければ、コンパイルできないようです。私はcygwinの下でgcc 3.4を使用していますので、コンパイラのバージョンの問題かもしれません - まだ使用しています bind(get <2、int、tuple >、_1) 私は " unknown型の最初の引数でバインドする不明な呼び出し " –