|
Boost : |
Subject: Re: [boost] [mpl] integral_c [type_traits] integral_constant limits
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-01-02 21:32:48
On 1/2/2011 11:00 AM, vicente.botet wrote:
> ----- Original Message -----
> From: "vicente.botet"<vicente.botet_at_[hidden]>
> To:<boost_at_[hidden]>
> Sent: Tuesday, November 16, 2010 10:15 PM
> Subject: Re: [boost] [mpl] integral_c [type_traits] integral_constant limits
>> ----- Original Message -----
>> From: "John Maddock"<boost.regex_at_[hidden]>
>> To:<boost_at_[hidden]>
>> Sent: Monday, November 15, 2010 10:17 AM
>> Subject: Re: [boost] [mpl] integral_c [type_traits] integral_constant limits
>>>> This means that with the current implementation we can not use
>>>> integral_constant with the max value of the type.
>>>>
>>>> Do you think this is a bug in integral_constant?
>>>
>>> It's nasty, but we do need MPL support in type_traits, so I don't see what
>>> we can really do about this?
>>>
>>> Can mpl be fixed not to cause numeric overflow when the value is at the
>>> limit of the range?
>>
>> I gues that it will be enough to overload the next and prior metafunctions on integral_c so the next and prior nestedtypes are no more nedeed, but I don't understand why the compiler is instantiating these types when not used yet. Could someone clarify if this instantiation is conforming to the standard?
>
> I have made some modification on Boost.MPL to don't include the prior and next nested types. Instead I have added a 'clone' metafunction that will not be instantiated if not explictly requested and that returns the integral type with a different parameter.
>
> template<AUX_WRAPPER_VALUE_TYPE M>
> struct clone {
> typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, M) ) type;
> };
>
> Of course I have needed to change the next and prior metafunctions to use tag dispatch.
>
> While running the regression on Boost.MPL I have found a problem: most of the types (iterators) that are used as parameter of next/prior don't have a tag nested type :(. I've added an artificial nested tag type on these types.
>
> In this way we are now able to instantiate integral constants with the max and min values without error.
>
> boost::mpl::integral_c<boost::intmax_t, 0x7FFFFFFFFFFFFFFFLL>
>
> Most of the modified code is protected with the macro BOOST_MPL_NEXT_PRIOR_EXT.
>
> I'm not sure this is the best way to workaround this BUG. Please, could you check the attached patches, and let me know if this patch can be included in trunk with minor modifications?
>
My bug report number 3779 is about this also. Please take a look at it
to make sure your fix also addresses that bug report. I assume it does
from your description above, but I just want to bring it to your
attention just in case.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk