Opened 11 years ago

Closed 2 years ago

#5768 closed Bugs (wontfix)

any_cast

Reported by: a.khawaldeh@… 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 Antony Polukhin, 9 years ago

This is discussed at the following thread.

comment:2 by Antony Polukhin, 9 years ago

Owner: changed from nasonov to Antony Polukhin

comment:3 by Antony Polukhin, 2 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.