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>);
불행하게도, 마지막 줄은 컴파일하지 않습니다 - 그것은 나에게 같은 메시지 제공 : 기본적으로
/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))
부스트를 사용하여 어떻게 할 수 있습니까?
Thanks - boost :: bind는 get <2, int, tuple에 대한 템플릿 선언과 마찬가지로 찾고 있습니다. 템플릿의 선언은을 얻지 못했습니다. 대신 을 얻으십시오. 그러나 bind를 사용하더라도 get2와 비슷한 함수 선언을 추가하지 않으면 컴파일 할 수 없습니다. Cygwin에서 gcc 3.4를 사용하고 있으므로 컴파일러 버전 문제 일 수 있습니다. - 여전히 사용 중입니다. bind (get <2, int, tuple >, _1) 줄을 따라 컴파일러 오류가 발생합니다. 알 수없는 유형의 첫 번째 인수로 바인딩 할 알 수없는 호출 ". –