Boost logo

Boost :

Subject: [boost] Iterator facade example could use some changes/documentation adjustments
From: Jacob McIntosh (nacitar_at_[hidden])
Date: 2010-02-09 16:12:25


My example here:
http://codepad.org/pH3pXAvb

As mentioned in the comment block at the codepad page:
http://www.boost.org/doc/libs/1_41_0/libs/iterator/doc/iterator_facade.html#wrap-up

The above link demonstrates in a linked-list scenario, using
is_convertible to handle
the conversion from non-const iterators to const iterators. This
works fine in the
example's linked list scenario, but it's likely than many users of
iterator_facade
will more generally copy this usage to their own container, from the example.

However, as my example demonstrates, in the case where the data lives
in contiguous
memory locations, or perhaps other scenarios, using is_convertible is very bad
for this purpose. It lets you convert from a derived class pointer to
a base class
pointer, and this is problematic if sizeof(base) is less than sizeof(derived)

See the below, very minimal example to illustrate my point.

Look at CFixedTest for my proposed replacement for is_convertible to
prevent this
undesirable behavior.

Seems to me that noting such behavior, or simply changing the example
code to not
allow the conversion (as my example does), would remedy the
misunderstanding/problem.

Just thought I'd contribute that - thanks,
nacitar


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk