Boost logo

Boost Users :

Subject: [Boost-users] Problem using boost::bind with std::map<>
From: przemyslaw.sliwa_at_[hidden]
Date: 2011-09-29 12:39:18


Hi,

I have the following definition of the classes
class DataRecordMap
{
        private:
                typedef boost::shared_ptr<const DataRecord >
DataRecordPtr;
                typedef std::pair<std::string, DataRecordPtr> key_type;
                typedef double value_type;

                struct keyComp
                {
                        bool operator() (const DataRecordMap::key_type
&lhs,
                                                         const
DataRecordMap::key_type &rhs) const;
                };

        private:
                typedef std::map<key_type, value_type, keyComp> map_type;

                const std::vector<size_t> m_index;
                map_type m_records;

        public:
                DataRecordMap(const std::vector<size_t> &idx);
                void add(DataRecordPtr secondKey, double value);
                double operator[] (const DataRecord &value) const;
                double& operator[] (const DataRecord &secondKey);

                friend std::ostream& operator << (std::ostream& out, const
DataRecordMap &records);

};

Then it fails to compile on this implementation:

double DataRecordMap::operator[] (const DataRecord &secondKey) const
{
        std::string firstKey(secondKey.compareKey(m_index)->signature());

        map_type::const_iterator findIt(std::find_if(m_records.begin(),
m_records.end(),
        boost::bind(&map_type::key_type::first, _1) == firstKey));
 
        if(findIt==m_records.end())
                THROW_EXCEPTION("Key " << firstKey << " not found in the
data records");

        return (*findIt).second;
}

Could someone please help me with it? The error is:

1>------ Build started: Project: compare, Configuration: Debug Win32
------
1>Compiling...
1>diffTool.cpp
1>d:\dev\soho_new\thirdparty\boost\bind\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(const boost::shared_ptr<X> &)' : could not deduce
template argument for 'const boost::shared_ptr<X> &' from 'const
std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type
1> ]
1> d:\dev\soho_new\thirdparty\boost\smart_ptr\shared_ptr.hpp(550) :
see declaration of 'boost::get_pointer'
1> d:\dev\soho_new\thirdparty\boost\bind\mem_fn.hpp(352) : see
reference to function template instantiation 'const R
&boost::_mfi::dm<R,T>::call<const U>(U &,const void *) const' being
compiled
1> with
1> [
1> R=std::string,
1>
T=std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>,
1> U=std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
1> ]
1> d:\dev\soho_new\thirdparty\boost\bind\bind.hpp(243) : see
reference to function template instantiation 'const R
&boost::_mfi::dm<R,T>::operator ()<A1>(const U &) const' being compiled
1> with
1> [
1> R=std::string,
1>
T=std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>,
1> A1=std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>,
1> U=std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
1> ]
1> d:\dev\soho_new\thirdparty\boost\bind\bind_template.hpp(318) :
see reference to function template instantiation 'R
boost::_bi::list1<A1>::operator ()<const
std::basic_string<_Elem,_Traits,_Ax>&,F,A>(boost::_bi::type<T>,F &,A
&,long)' being compiled
1> with
1> [
1> R=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> A1=boost::arg<1>,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1>
F=boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,
1> A=const boost::_bi::list1<const std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
&>,
1> T=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &
1> ]
1> d:\dev\soho_new\thirdparty\boost\bind\bind.hpp(237) : see
reference to function template instantiation 'const
std::basic_string<_Elem,_Traits,_Ax>
&boost::_bi::bind_t<R,F,L>::eval<const boost::_bi::list1<A1>>(A &)' being
compiled
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> R=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1>
F=boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,
1> L=boost::_bi::list1<boost::arg<1>>,
1> A1=const std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
&,
1> A=const boost::_bi::list1<const std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
&>
1> ]
1> d:\dev\soho_new\thirdparty\boost\bind\bind.hpp(303) : see
reference to function template instantiation 'const
std::basic_string<_Elem,_Traits,_Ax> &boost::_bi::list1<A1>::operator
[]<const
std::basic_string<_Elem,_Traits,_Ax>&,boost::_mfi::dm<R,T>,boost::_bi::list1<boost::arg<I>>>(boost::_bi::bind_t<const
std::basic_string<_Elem,_Traits,_Ax> &,F,L> &) const' being compiled
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> A1=const std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
&,
1> R=std::string,
1>
T=std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>,
1> I=1,
1>
F=boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,
1> L=boost::_bi::list1<boost::arg<1>>
1> ]
1> d:\dev\soho_new\thirdparty\boost\bind\bind_template.hpp(47) :
see reference to function template instantiation 'R
boost::_bi::list2<A1,A2>::operator ()<bool,F,boost::_bi::list1<const
std::pair<_Ty1,_Ty2> &>>(boost::_bi::type<T>,F &,A &,long)' being compiled
1> with
1> [
1> R=bool,
1> A1=boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,boost::_bi::list1<boost::arg<1>>>,
1> A2=boost::_bi::value<std::string>,
1> F=boost::_bi::equal,
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type,
1> T=bool,
1> A=boost::_bi::list1<const std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
&>
1> ]
1> c:\program files\microsoft visual studio
8\vc\include\algorithm(87) : see reference to function template
instantiation 'bool boost::_bi::bind_t<R,F,L>::operator
()<std::pair<_Ty1,_Ty2>>(const A1 &)' being compiled
1> with
1> [
1> R=bool,
1> F=boost::_bi::equal,
1> L=boost::_bi::list2<boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,boost::_bi::list1<boost::arg<1>>>,boost::_bi::value<std::string>>,
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type,
1> A1=std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>
1> ]
1> c:\program files\microsoft visual studio
8\vc\include\algorithm(96) : see reference to function template
instantiation '_InIt
std::_Find_if<std::_Tree<_Traits>::const_iterator,_Pr>(_InIt,_InIt,_Pr)'
being compiled
1> with
1> [
1>
_InIt=std::_Tree<std::_Tmap_traits<`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type,`anonymous-namespace'::DataRecordMap::keyComp,std::allocator<std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>>,false>>::const_iterator,
1>
_Traits=std::_Tmap_traits<`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type,`anonymous-namespace'::DataRecordMap::keyComp,std::allocator<std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>>,false>,
1>
_Pr=boost::_bi::bind_t<bool,boost::_bi::equal,boost::_bi::list2<boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,boost::_bi::list1<boost::arg<1>>>,boost::_bi::value<std::string>>>
1> ]
1> d:\dev\ownprogs\compare\compare\difftool.cpp(166) : see
reference to function template instantiation '_InIt
std::find_if<std::_Tree<_Traits>::const_iterator,boost::_bi::bind_t<R,F,L>>(_InIt,_InIt,_Pr)'
being compiled
1> with
1> [
1>
_InIt=std::_Tree<std::_Tmap_traits<`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type,`anonymous-namespace'::DataRecordMap::keyComp,std::allocator<std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>>,false>>::const_iterator,
1>
_Traits=std::_Tmap_traits<`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type,`anonymous-namespace'::DataRecordMap::keyComp,std::allocator<std::pair<const
`anonymous-namespace'::DataRecordMap::key_type,`anonymous-namespace'::DataRecordMap::value_type>>,false>,
1> R=bool,
1> F=boost::_bi::equal,
1> L=boost::_bi::list2<boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,boost::_bi::list1<boost::arg<1>>>,boost::_bi::value<std::string>>,
1>
_Pr=boost::_bi::bind_t<bool,boost::_bi::equal,boost::_bi::list2<boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,`anonymous-namespace'::DataRecordMap::DataRecordPtr>>,boost::_bi::list1<boost::arg<1>>>,boost::_bi::value<std::string>>>
1> ]
1>d:\dev\soho_new\thirdparty\boost\bind\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce
template argument for 'const std::auto_ptr<_Ty> &' from 'const
std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type
1> ]
1> d:\dev\soho_new\thirdparty\boost\get_pointer.hpp(25) : see
declaration of 'boost::get_pointer'
1>d:\dev\soho_new\thirdparty\boost\bind\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(T *)' : could not deduce template argument for 'T *'
from 'const std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type
1> ]
1> d:\dev\soho_new\thirdparty\boost\get_pointer.hpp(18) : see
declaration of 'boost::get_pointer'
1>d:\dev\soho_new\thirdparty\boost\bind\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(const boost::reference_wrapper<T> &)' : could not
deduce template argument for 'const boost::reference_wrapper<T> &' from
'const std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const `anonymous-namespace'::DataRecordMap::key_type,
1> _Ty2=`anonymous-namespace'::DataRecordMap::value_type
1> ]
1> d:\dev\soho_new\thirdparty\boost\ref.hpp(182) : see declaration
of 'boost::get_pointer'
1>Build log was saved at
"file://d:\Dev\OwnProgs\compare\compare\Debug\BuildLog.htm"
1>compare - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

___________________________________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited.

Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-845C5H for additional disclosures.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net