c++ - Boost::tuple - assigning to get<>() -
the following fails compile on assignment t.get<1>().
struct pull_from_memory { pull_from_memory(memorybank &m) : m_map(m) {}; void operator()(boost::tuple<string&, string&> &t ) { memorybank::iterator i; if ( ( = m_map.find(t.get<0>())) != m_map.end() ) { t.get<1>() = *i; // compilation error } } private: memorybank &m_map; };
the error message, fwiw, is:
tom.cpp: in member function 'void pull_from_memory::operator()(boost::tuples::tuple<std::string&, std::string&, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>&)': tom.cpp:424: error: no match 'operator=' in '((boost::tuples::tuple<std::string&, std::string&, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>*)t)->boost::tuples::tuple<std::string&, std::string&, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>::<anonymous>.boost::tuples::cons<ht, tt>::get [with int n = 1, ht = std::string&, tt = boost::tuples::cons<std::string&, boost::tuples::null_type>]() = i.boost::unordered_detail::hash_iterator<a, g>::operator* [with = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, g = boost::unordered_detail::ungrouped]()' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:510: note: candidates are: std::basic_string<_chart, _traits, _alloc>& std::basic_string<_chart, _traits, _alloc>::operator=(const std::basic_string<_chart, _traits, _alloc>&) [with _chart = char, _traits = std::char_traits<char>, _alloc = std::allocator<char>] /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:518: note: std::basic_string<_chart, _traits, _alloc>& std::basic_string<_chart, _traits, _alloc>::operator=(const _chart*) [with _chart = char, _traits = std::char_traits<char>, _alloc = std::allocator<char>] /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:529: note: std::basic_string<_chart, _traits, _alloc>& std::basic_string<_chart, _traits, _alloc>::operator=(_chart) [with _chart = char, _traits = std::char_traits<char>, _alloc = std::allocator<char>]
update 1: after correcting fact map.find returns pair, link error, apparently related instantiating template
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h: in function '_funct std::for_each(_iiter, _iiter, _funct) [with _iiter = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _funct = bind_from_memory]': /mxhome/charrison/git/sdcore/libs/commutils/test/../include/block.h:160: instantiated 'void block::traverse_record(const d_recordtype&, function) [with function = bind_from_memory]' tom.cpp:473: instantiated here /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:4200: error: no match call '(bind_from_memory) (boost::tuples::cons<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::tuples::cons<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::tuples::null_type> >)' tom.cpp:460: note: candidates are: void bind_from_memory::operator()(boost::tuples::tuple<const std::string&, std::string&, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>&)
your problem you're expecting *i
std::string
, isn't. it's (reference to) std::pair<std::string,std::string>
.
that's how iterators maps work.
try instead:
t.get<1>() = i->second; //if want value corresponding key
Comments
Post a Comment