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:

As mentioned in the comment block at the codepad page:

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
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

Just thought I'd contribute that - thanks,

Boost list run by bdawes at, gregod at, cpdaniel at, john at