|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-04-01 14:35:59
AMDG
Johannes Stallkamp wrote:
> Hello there,
>
>
> Short version:
> Are there any reasons, why base class access is currently not
> allowed/implemented in boost::function (via target() function)?
>
Short answer: It's not at all easy to implement.
> Long version/explanation/scenario:
>
Long answer:
Boost.Function stores a pointer, but it's a void pointer so it loses all
type information. The type information is stored separately, using
std::type_info. With this setup, there is no way to determine
whether the type that you ask for is a base of the stored type.
The only way to implement this is to create a class the inherits
multiply from the stored type and a common base. This allows
the use of dynamic_cast to cross cast. This unfortunately requires
that it be possible to derive from the stored type, so built-ins become
a special case. In addition, it makes the small buffer optimization
difficult to implement seriously hurting performance even when this
feature is not used.
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net