我有以下代码(在 MSVC9 上使用 boost 1.55):
struct pair_first_impl
{
template<class TPair> struct result { typedef typename TPair::first_type type; };
template<class TPair>
typename TPair::first_type const& operator() (TPair const& pair) const
{
return pair.first;
}
template<class TPair>
typename TPair::first_type& operator() (TPair& pair)
{
return pair.first;
}
};
static phx::function<pair_first_impl> pair_first;
int test()
{
std::map<int, std::string> mymap;
std::find_if(mymap.begin(), mymap.end(), pair_first(_1) == 1);
}
我收到一个关于 的编译器错误pair_first_impl::result::type
,它说:
error C2825: 'TPair': must be a class or namespace when followed by '::'
see reference to class template instantiation 'pair_first_impl::result<TPair>' being compiled
with
[
TPair=const pair_first_impl (std::pair<const int,std::string> )
]
出于某种原因,它看起来像是将函数类型(?)传递给我的TPair
模板参数,而不是std::pair
直接传递类型。
谁能帮我弄清楚我在这里做错了什么?