Foreach implementation in C++, a Poor man's approach -


there happy people working boost , qt. in current "embedded" project have use home-made container classes. ok, enough complaining.

i've tried implement easy , self-contained foreach that:

#define foreachstring(s,c) tstring s;\         ( int i=0; i<c.getsize() && (!!(&(s=c[i]))); ++i  ) 

it iterates through string-list has op[] , getsize() methods. e.g.:

tstringlist tables; foreachstring( table, tables ) {   //do sth. tab. } 

of cause, ugly thing is, each container type requires own macro. therefore question: possible container independant , still self contained (all required stuff within macro definition)?

regards, valentin

perhaps parameterise on type t:

#define foreach(t,s,c) t s;\      ( int i=0; i<c.getsize() && (!!(&(s=c[i]))); ++i  )   tstringlist tables;  foreach( tstring, table, tables )  {    //do sth. tab.  }  

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -