Angus Leeming <[EMAIL PROTECTED]> writes:

| Angus Leeming wrote:
>
>> Angus Leeming wrote:
>>> Lars Gullik Bjønnes wrote:
>>>> note the member function boost::any:type
>>> 
>>> Bingo! No need for exceptions after all.
>>> Many thanks, Lars.
>> 
>> Next iteration. I think that this is ready to convert into InsetExternal
>> code.
>
| Hmmppfff! trying to do so, I get this
>
| ../../../boost/boost/any.hpp: In function `ValueType boost::any_cast(const
|    boost::any&) [with ValueType = lyx::external::RotationCommandFactory]':
| ../../../src/insets/ExternalTemplate.h:54:   instantiated from `void 
| lyx::external::TransformStore::getTransformer(const Data&, Transformer&) 
| const [with Factory = lyx::external::RotationCommandFactory, Data = 
| lyx::external::RotationData, Transformer = std::auto_ptr<const 
| lyx::external::TransformCommand>]'
| ../../../src/insets/insetexternal.C:790:   instantiated from here
| ../../../boost/boost/any.hpp:174: exception handling disabled, use 
| -fexceptions to enable
>
|     template<typename ValueType>
|     ValueType any_cast(const any & operand)
|     {
|         const ValueType * result = any_cast<ValueType>(&operand);
|         if(!result)
|             throw bad_any_cast();
|         return *result;
|     }
>
| Could I insert 
|         BOOST_ASSERT(result);
| in its place please? The code is safe:
>
|                 if (any_factory.type() != typeid(Factory) ||
|                     any_data.type() != typeid(Data))
|                         return;
>
|                 Factory * factory = boost::any_cast<Factory>(any_factory);
|                 if (!factory.empty())
|                         transformer = factory(data);

But aren't you using the wrong any_cast here?
Shouldn't you use boost::any_cast<Factory*>?

Hmm... there is something I do not understand here. any_cast with a
refernece or a value type will throw if cast to the wrong type, but if
a pointer type then 0 will be returned when wrong type is used?

-- 
        Lgb

Reply via email to