Question about using Boost::for_each function to set a local variable if a condition is met
Hi, I am trying to Boost::for_each function to set a local variable if all elements in this is DEFAULT type. Here is my code, but I don't know how to implement the last part of the if_then call. boolean rtnValue = false; for_each(mylist.begin(), mylist.end(), if_then( bind(&ListItem::getType, _1) == DEFAULT, set the local value to true if true if all of them are DEFAULT type )); if you can give me some pointers, I will be appreciated. Thank you.
On 1/30/07, Meryl Silverburgh
Hi,
I am trying to Boost::for_each function to set a local variable if all elements in this is DEFAULT type.
Here is my code, but I don't know how to implement the last part of the if_then call.
boolean rtnValue = false;
bool rtnValue = true; // assume true
for_each(mylist.begin(), mylist.end(), if_then( bind(&ListItem::getType, _1) == DEFAULT, set the local value to true if true if all of them are DEFAULT type ));
bind(&ListItem::getType, _1) != DEFAULT, set the local value to false));
if you can give me some pointers, I will be appreciated.
ie start with true, set it to false if any are NOT the default. Not sure how to bind that though - probably need 'boost::ref(rtnValue) = false' or something like that.
Thank you.
HTH, Tony
Gottlob Frege wrote:
On 1/30/07, Meryl Silverburgh
wrote: Hi,
I am trying to Boost::for_each function to set a local variable if all elements in this is DEFAULT type.
Here is my code, but I don't know how to implement the last part of the if_then call.
boolean rtnValue = false;
bool rtnValue = true; // assume true
for_each(mylist.begin(), mylist.end(), if_then( bind(&ListItem::getType, _1) == DEFAULT, set the local value to true if true if all of them are DEFAULT type ));
bind(&ListItem::getType, _1) != DEFAULT, set the local value to false));
bool rtnValue = find_if( mylist.begin(), mylist.end(), bind(&ListItem::getType, _1) != DEFAULT ) == mylist.end();
On 1/30/07, Peter Dimov
Gottlob Frege wrote:
On 1/30/07, Meryl Silverburgh
wrote: Hi,
I am trying to Boost::for_each function to set a local variable if all elements in this is DEFAULT type.
Here is my code, but I don't know how to implement the last part of the if_then call.
boolean rtnValue = false;
bool rtnValue = true; // assume true
for_each(mylist.begin(), mylist.end(), if_then( bind(&ListItem::getType, _1) == DEFAULT, set the local value to true if true if all of them are DEFAULT type ));
bind(&ListItem::getType, _1) != DEFAULT, set the local value to false));
bool rtnValue = find_if( mylist.begin(), mylist.end(), bind(&ListItem::getType, _1) != DEFAULT ) == mylist.end();
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks for the help.
participants (3)
-
Gottlob Frege
-
Meryl Silverburgh
-
Peter Dimov