Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2005-02-18 04:06:28


Vladimir Prus wrote:
> Given that overall reaction is positive, I'll make the change,
starting with
> the 'cast to reference' logic I wanted in the first place.
>
> The only difference between my version and the one you mention above
is this
> snippet in 'any_cast':
>
> #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
> // Please use BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION
macro
> // to generate specialization of remove_reference for your
class
> // See type traits library documentation for details
> BOOST_STATIC_ASSERT(!::boost::is_reference<nonref>::value);
> #endif
>
>
> It looks to me that this assert will always be triggered when your
pass
> reference type and BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION is
defined,
> right? The assert will fire even if used has specialized
remove_reference,
> no? If that's true, the comment is not correct and casting to
reference is
> just not supported for broken compilers.

On broken compilers the assert for any_cast<int cv&> fires only if this
thing is not in TU before first use of any_cast<int v&>:

BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(int)

IMHO, if it's there, everything should work. BTW, there is a testcase in
my
earlier post in that thread. You can try to comment one such workaround
to see
the difference on a broken compiler or with
BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION defined.

Be careful, don't mix up the correct patch with previous version that
comes
with the test.

> I see that your patch also:
> 1. Strips cv-qualification in constructor (which is reasonable).

const is already stripped because ctor's argument is 'const ValueType &
value'.
So, it's only for volatile. remove_cv is used only to avoid inclusion of
remove_volatile.hpp.

> 2. Strips cv-qualification when casting to pointer.
>
> Why the second aspect is needed?

Quoting myself:

> I forgot to mention that the original version has small problem with
> any_cast
> to const type. If any stores T and you cast it to T const you're
trying
> this sequence of static_casts:
>
> holder<T>* -> (in ctor) -> placeholder* -> (in any_cast) -> holder<T>
const>*
>
> Obviously, it's not getting back to original holder<T> type.

-- 
Alexander Nasonov

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk