T. Lovset
2004-09-09 10:11:11 UTC
Having tried before, but only got a few (grumpy) answers, I would like
to see some more solid objections on this proposal:
Modifying boost::shared_ptr from
template <class T> class shared_ptr {
...
public:
shared_ptr() : px(0), pn() {}
to
template <class T> class shared_ptr {
...
private:
struct null_tag {};
public:
shared_ptr(null_tag* = 0) : px(0), pn() {}
shared_ptr& operator=(null_tag*) { reset(); return *this; }
leaving everything else unchanged, will give these benefits:
1. It allows
void someFunc(const boost::shared_ptr<SomeClass>& ptr = NULL);
someFunc(NULL);
which currently must be written (!!):
void someFunc(const boost::shared_ptr<SomeClass>& ptr =
boost::shared_ptr<SomeClass>());
someFunc(boost::shared_ptr<SomeClass>());
2. It allows
boost::shared_ptr<SomeClass> ptr1(NULL);
boost::shared_ptr<SomeClass> ptr2 = NULL;
which both currently produce compiler errors.
3. It allows
ptr = NULL;
which currently must be written
ptr.reset();
4. It simplifies converting raw pointers to shared_ptrs, and the usage
is intuitive to new users.
5. This proposal introduces no other side-effects, and has no backward
compability issues.
Note: This proposal cannot be applied on auto_ptr because of its
special copy semantics, but these two classes have already different
usage and application areas. However, the proposal can by applied on
most other smart pointers.
Not that I find this to be an important improvement, I do find it a
bit frustrating how difficult it is to gain sympathy on such an
obvious (to me) and small matter. Not really. :D
++
T. Lovset
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
to see some more solid objections on this proposal:
Modifying boost::shared_ptr from
template <class T> class shared_ptr {
...
public:
shared_ptr() : px(0), pn() {}
to
template <class T> class shared_ptr {
...
private:
struct null_tag {};
public:
shared_ptr(null_tag* = 0) : px(0), pn() {}
shared_ptr& operator=(null_tag*) { reset(); return *this; }
leaving everything else unchanged, will give these benefits:
1. It allows
void someFunc(const boost::shared_ptr<SomeClass>& ptr = NULL);
someFunc(NULL);
which currently must be written (!!):
void someFunc(const boost::shared_ptr<SomeClass>& ptr =
boost::shared_ptr<SomeClass>());
someFunc(boost::shared_ptr<SomeClass>());
2. It allows
boost::shared_ptr<SomeClass> ptr1(NULL);
boost::shared_ptr<SomeClass> ptr2 = NULL;
which both currently produce compiler errors.
3. It allows
ptr = NULL;
which currently must be written
ptr.reset();
4. It simplifies converting raw pointers to shared_ptrs, and the usage
is intuitive to new users.
5. This proposal introduces no other side-effects, and has no backward
compability issues.
Note: This proposal cannot be applied on auto_ptr because of its
special copy semantics, but these two classes have already different
usage and application areas. However, the proposal can by applied on
most other smart pointers.
Not that I find this to be an important improvement, I do find it a
bit frustrating how difficult it is to gain sympathy on such an
obvious (to me) and small matter. Not really. :D
++
T. Lovset
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]