Opened 11 years ago
Closed 2 years ago
#5768 closed Bugs (wontfix)
any_cast
Reported by: | Owned by: | Antony Polukhin | |
---|---|---|---|
Milestone: | To Be Determined | Component: | any |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
assume we have a class Base, and other class Derived that inherits Base.
I can write
boost::any a = new Derived;
so, the following code
Derived* d = any_cast<Derived*>(a);
will work good, but!!
Base* b = any_cast<Base*>(a);
will fail.
i.e boost::any_cast could not work with inheritance and polymorphism.
You may wonder why this is needed? but I did faced this case.
I solved this problem in boost::any on my machine, and I thought to share this with others, so if this sounds useful to you, please tell me how can I add my code to boost
many thanks.
Change History (3)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Owner: | changed from | to
---|
comment:3 by , 2 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The proposed implementation throws a held type and tries to catch it by base type. This is a quite curious technique!
Unfortunately it's not usable for production due to the exceptions being too heavy to throw and catch.
This is discussed at the following thread.