Boost logo

Boost Users :

From: Alexander Shyrokov (shirokov_at_[hidden])
Date: 2006-09-15 17:51:35


> In such a situation I tend to define my own nullptr:
>
> struct nullptr_t
> {
> template<class T> operator T* () const { return 0; }
> } nullptr;
>
> and use that instead of NULL.
Thanks, Peter. Both casting and nullptr worked fine. But it brings me to
a bigger question, should I bother replacing this code:

struct c{void f(char*){}};
typedef std::map<int,c*> TMap;
TMap a;
for(TMap::iterator i=a.begin();i!=a.end();++i)(*a)->second.f(NULL):

with the more complex code like this:

struct c{void f(char*){}};
struct nullptr_t{template<class T>operator T*()const{return 0;}}nullptr;
typedef std::map<int,c*> TMap;
TMap a;
std::for_each(a.begin(),a.end(),
        boost::bind(&c::f,
                boost::bind(&TMap::value_type::second,_1),
                nullptr)
        );

I know there should be a line. But I am new to the algorithm's way :)
Thanks.

-- 
Regards,
     Alexander.                http://sjcomp.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net