![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
Member
Join Date: Jul 2003
Posts: 97
|
How often have you written some thing like this:
Code:
shouldn't there be a easier more explicit way? of course there is, using std::for_each and a simple functor we get this: Code:
ahhh, doesn't that feel nice? less to type extra clarity *and* it could actually give you a speed gain becuase c.end() isn't recalculated oh and that it's less error prone is just an added bonus =) |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
and never forget, boost::checked_delete or boost::checked_deleter (spelling..) does exactly that..
![]() but yes, its great for container cleanup..
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2003
Posts: 97
|
I hadn't had the pleasure to use boost much but I really should have a look at it one of theese days.
For a "safe delete" you could use this Code:
strictly speaking you should actually never need to test p against NULL because according to the standard delete NULL is safe (as is free(NULL); ) but some compilers on small platforms are known to get this wrong and do funny things when trying to delete a NULL pointer. |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
yep, its useless, the if(p) delete p. but on stupid compilers useless stuff gets quite important sometimes
![]() like #define for if(0) {} else for and similar stuff ![]()
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
|
#5 | |
|
Member
Join Date: Jul 2003
Posts: 97
|
Quote:
![]() |
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
yeah, good old days
![]()
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|