From: Augustus Saunders (infinite_8_monkey_at_[hidden])
Date: 2002-12-11 18:27:41
I like the optional-as-pointer usage, and I would prefer it if I
could write generic code where pointers and optionals are completely
interchangeable. However, it isn't really possible to take this all
the way, and we may be luring generic programmers into a trap by
making them think pointers and optionals are interchangeable.
This is of course because the two optionals never point to the same
// assume p1, p2 initialized
if (p1 == p2)
*p1 = 5;
assert(5 == *p2); // holds true for pointers but not for optionals
Violating this assumption would break code that wants to treat them
Some people want to define:
o1 == o2 iff (o1 && o2 && *o1 == *o2) || (!o1 && !o2)
whereas (smart)pointers define:
p1 == p2 iff (p1 && p2 && &*p1 == &*p2) || (!p1 && !p2)
I don't think that it would be possible to code around this point
generically. Now, having said all of that, I still like the pointer
notation when I understand the lack of equivalence because it is very
concise. Maybe this is just a new concept that needs to be defined
so you can specify it in the requirements to your generic code.
Obviously, there is a lot of generic code that you could write that
doesn't depend on either of the above equivalences--smart pointers
are still useful even though they can't be used as iterators.
Although this is more insidious; it's not the lack of an operator
(++, --) but a redefinition with different semantics. Generic code
that relied on pointer semantics would compile when given an optional
but just wouldn't work.
So *I* like optional and would use it like it is, but I'm undecided
whether or not this style interface is just begging for programmer
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk