Rewrite defines as c++ -


hy, it's possible rewrite 2 definitions c++ code functiom? want remove #define

define 1:

#define do_all_block_ip(iter)   \     ((iter) = m_block_ip.begin(); (iter) != m_block_ip.end(); ++(iter)) 

define2 :

#define do_all_block_exception(iter) \     ((iter) = m_block_exception.begin(); (iter) != m_block_exception.end(); ++(iter)) 

not directly - syntax do_all_block_ip(iter) {/* code here */} not valid if do_all_block_ip function.

you use new c++ range syntax, long don't need use iterator directly (only values):

for(auto& value : m_block_ip) {     // code here } 

if must use function reason, pass functor, , use lambda expression define that:

// definition (assuming m_block_ip vector of block_ip_t) void do_all_block_ip(std::function<void(std::vector<block_ip_t>::iterator)> f) {     for(auto iter = m_block_ip.begin(); iter != m_block_ip.end(); iter++)         f(iter); }  // alternate definition *may* more efficient, more cumbersome template<class f_class> void do_all_block_ip(f_class f) {     for(auto iter = m_block_ip.begin(); iter != m_block_ip.end(); iter++)         f(iter); }  // how call do_all_block_ip([&](std::vector<block_ip_t>::iterator iter) {     // code here }); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -