Boost logo

Boost :

From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2007-10-09 19:42:27

Fernando Cacciola wrote:
>Pendantically speaking, there is no such thing as a "safe
>While this is somewhat permmited in production code where the typical
>deadline is yesterday, here in boost you need a definite need for using

>Anyway, can you explain in some detail how doesn't your adaptation
>avoid copying?

The ability to modify the contents of an object in place without copying
was the original intent of the entire exercise in generic programming.

If you have two classes

class A {...};
class B : public A {...};

or by composition

class A {...};
class B { A a; };

You know it is safe to reinterpret_cast A to B and B to A (because they
are the same data, and differ in behavior only.) You can take an object
of type A, cast it to B, use the behaviors of B to modify it *in place*
and cast it back to an A if you like. I don't believe that
reinterpret_cast shouldn't be permitted. There are cases where reading
the C++ standard will inform a developer that reinterpret_cast is safe
and if the compiler causes a problem it is because of a problem in the
compiler, not the code. Specifically, I submit that inheritance and
composition are such cases provided that additional data members are not
added in the subtype or composed type. I don't make the user
reinterpret_cast for themselves, but instead provide mimic() and yield()
functions for casting to and from my Concept type. If this use of
reinterpret_cast to change the behavior of an object is unacceptable for
a boost submission that pretty much closes the whole case, since the
design pattern depends upon it in a very necessary way. Obviously, we
should sort this issue out.

There was once an experiment on group learning conducted on monkeys. A
group of monkeys in a cage had an electrified banana lowered into it
periodically. They quickly learned not to touch it. When new monkeys
were introduced into the cage the other monkeys went to extreme measures
to prevent them from touching the electric banana. Old monkeys were
removed and new monkeys added until eventually no monkey present had
ever touched or seen another monkey touch the banana, but still they
prevented any new monkey from breaking the taboo. At that point it
became impossible for the monkeys to ever learn that the banana was
safe, because even if they touched it and didn't get shocked they
wouldn't know that the circumstance had changed.

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