2012-04-06 8 views
0

私は、次の機能に問題が生じています:TR1のバインド(む〜!)

Island::save関数はバインドを使用するため、この

virtual void save(std::ostream& out) const; 

このフォーマットのように見えます

typedef std::tr1::shared_ptr<Island> Island_sp_t; 
typedef map<string, Island_sp_t>::value_type island_map_pair; 

std::map<std::string, Island_sp_t> Island_ptr_map; 


void Model::save_all(ostream& out) 
{ 
    for_each(Island_ptr_map.begin(), Island_ptr_map.end(), bind(&Island::save, 
      bind<Island_sp_t>(&island_map_pair::second, _1), ref(out))); 
} 

これまでのマップではうまくいきましたが、この特殊なケースでは、g ++ 4.1.2で次のフラグを使って次のエラーが発生します。

g++ -c Pedantic -ansi -Wall 


/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/bind_iterate.h: In member function ‘typename std::tr1::result_of<_Functor()(typename std::tr1::result_of<std::tr1::_Mu<_T1, std::tr1::is_bind_expression<_T1>::value, (std::tr1::is_placeholder<_T1>::value > 0)>()(_T1, std::tr1::tuple<_U1, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass>)>::type, typename std::tr1::result_of<std::tr1::_Mu<_T1, std::tr1::is_bind_expression<_T1>::value, (std::tr1::is_placeholder<_T1>::value > 0)>()(_T2, std::tr1::tuple<_U1, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass>)>::type)>::type std::tr1::_Bind<_Functor()(_T1, 
_T2)>::operator()(_U1&) [with _U1 = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>, std::tr1::shared_ptr<Island> >, _Functor = std::tr1::_Mem_fn<void (Island::*)(std::ostream&)const>, _T1 = std::tr1::_Bind_result<std::tr1::shared_ptr<Island>, std::tr1::_Mem_fn<std::tr1::shared_ptr<Island> std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>, std::tr1::shared_ptr<Island> >::*>()(std::tr1::_Placeholder<1>)>, _T2 = std::tr1::reference_wrapper<std::basic_ostream<char, std::char_traits<char> > >]’: /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:159: instantiated from ‘_Function std::for_each(_InputIterator, 
_InputIterator, _Function) [with _InputIterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tr1::shared_ptr<Island> > >, _Function = std::tr1::_Bind<std::tr1::_Mem_fn<void (Island::*)(std::ostream&)const>()(std::tr1::_Bind_result<std::tr1::shared_ptr<Island>, std::tr1::_Mem_fn<std::tr1::shared_ptr<Island> std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> 
>, std::tr1::shared_ptr<Island> >::*>()(std::tr1::_Placeholder<1>)>, std::tr1::reference_wrapper<std::basic_ostream<char, std::char_traits<char> > >)>]’ Model.cpp:179: instantiated from here /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/bind_iterate.h:45: error: no match for call to ‘(std::tr1::_Mem_fn<void (Island::*)(std::ostream&)const>) (std::tr1::shared_ptr<Island>, std::basic_ostream<char, std::char_traits<char> >&)’ /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/functional_iterate.h:261: note: candidates are: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_T1)const>::operator()(const _Class&, _T1) const [with 
_Res = void, _Class = Island, _T1 = std::ostream&] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/functional_iterate.h:267: note:     _Res std::tr1::_Mem_fn<_Res (_Class::*)(_T1)const>::operator()(const _Class*, _T1) const [with 
_Res = void, _Class = Island, _T1 = std::ostream&] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/functional_iterate.h:274: note:     _Res std::tr1::_Mem_fn<_Res (_Class::*)(_T1)const>::operator()(_Tp&, _T1) const [with _Tp = std::tr1::shared_ptr<Island>, _Res = void, _Class = Island, _T1 = std::ostream&] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/tr1/bind_iterate.h:45: error: return-statement with a value, in function returning 'void' make: *** [Model.o] Error 1 

すべてのタイプがfunctional_iterate.h:274の候補とうまく一致するように見えるため、このエラーで非常に混乱します。私は何が欠けているかについての任意のアイデア?以下のようになります。アルゴリズムは以下のように知っているしたい人のため

答えて

0

は、私は、私の2番目のバインド引数に「ポーラ」が必要:

for_each(Island_ptr_map.begin(), Island_ptr_map.end(), bind(&Island::save, 
      bind<const Island_sp_t>(&island_map_pair::second, _1), ref(out))); 
関連する問題