是否可以执行以下操作。Boost元组+变换
说我升压元组具有<std::string, T>
我想使用std ::变换+ mem_fun在相应的矢量仅插入的std :: string元素。是否有可能还是我们需要使用一个循环和的push_back(获得< 0>)...
即下面不喜欢编译...(未知类型...)
result.resize(storage.size())
std::transform(storage.begin(), storage.end(), result.begin(), std::mem_fun(&boost::get<0>));
这里是(尝试一个评论)一个例子:
#include <boost/tuple/tuple.hpp>
#include <vector>
#include <string>
#include <algorithm>
#include <boost/bind.hpp>
template <typename T>
class TestClass
{
private:
typedef boost::tuple<std::string,T> PairType;
std::vector<PairType> storage;
public:
void extract(std::vector<std::string> &result)
{
result.resize(storage.size());
std::transform(storage.begin(), storage.end(), result.begin(), boost::bind(&PairType::get<0>, _1));
}
};
int main(int argc, char**argv)
{
TestClass<int> bb;
std::vector< std::string> result;
bb.extract(result);
return 0;
}
g++ test.cpp
test.cpp: In member function `void TestClass<T>::extract(std::vector<std::string, std::allocator<std::string> >&)':
test.cpp:17: error: expected primary-expression before ',' token
test.cpp: In member function `void TestClass<T>::extract(std::vector<std::string, std::allocator<std::string> >&) [with T = int]':
test.cpp:26: instantiated from here
test.cpp:17: error: address of overloaded function with no contextual type information
您需要提供更多的代码和编译器呕吐。 – 2011-01-13 01:42:54