C++ What is the std::for_each() function parameter type? -


here couple of snippets first successful use of std::for_each() construct:

struct add_to_memory {     void operator()(const boost::tuple<const string&, const string&> &t ) {         m_map.insert(make_pair(t.get<0>(),t.get<1>()));     }     add_to_memory(memorybank &m) : m_map(m) {}; private:     memorybank &m_map; };  void memorize(block &block) {     block.get_record_types(record_type_set);     boost_foreach(d_recordtype_set::value_type rec_type, record_type_set) {         md_zip_range zipper = block.make_field_value_zip_range(rec_type);         std::for_each(zipper.first, zipper.second, add_to_memory(memory_bank));     } } 

i want change "memorize" function accepts additional parameter - function or functor or whatever add_to_memory() is. can't figure out type use in signature.

void scan_block_and_apply_function( block&, ..?.. ); 

i'm using [read: "stuck with"] g++ 4.4, it's safe haven't got c++11. should signature be? , how should scan_block_and_apply_function() called?

this done through templates:

template <typename memorybankfunctor> void memorize(block &block, memorybankfunctor functor) {     block.get_record_types(record_type_set);     boost_foreach(d_recordtype_set::value_type rec_type, record_type_set) {         md_zip_range zipper = block.make_field_value_zip_range(rec_type);         std::for_each(zipper.first, zipper.second, functor);     } } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -