Boost logo

Boost :

Subject: Re: [boost] [math] common_factor template parameters
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-06-27 05:25:13


----- Original Message -----
From: "John Maddock" <boost.regex_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, June 26, 2010 6:22 PM
Subject: Re: [boost] [math] common_factor template parameters

>
>>static_gcc and static_lcm have unsigned long parameters.
>>
>>template < unsigned long Value1, unsigned long Value2 >
>>struct boost::math::static_gcd;
>>
>>Could these be changed to uintmax_t?
>
> I would think so yes.

Do you need I make a ticket?

>>Is there any deep reason to don't define them for singed integers
>>(intmax_t) also?
>
> No, since the result for both functions is always taken as positive for one
> or more negative arguments. However.... unless we change the interface,
> it's hard to see how to accomplish this easily? Particularly as the
> unsigned version has a greater range?
>
> Note that if the arguments might be negative then you could just write:
>
> static_lcm<(arg1 < 0 ? -arg1 : arg1), (arg2 < 0 ? -arg2 : arg2)>::value
>
> to achieve the same effect.

Ok, I will use it in this way.

Joel Falcou suggested on another thread to define MPL integral constant metafunction for static_abs and static_sign.

namespace XXX {
template <typename ICT>
abs : mpl::if_<is_unsigned<ICT::value_type>,
            ICT,
            mpl::integral_c<make_unsigned<ICT::value_type>,
                (ICT::value < 0 ? -ICT::value : ICT::value)
>
> {};
}

Murillo, a GSOC student, is working on some metafunctions for integers including between others abs and sign.
What do you think about a MPL integral constant metafunction having as parameters integral constant types on top of static_lcm?

namespace XXX {

template <typename ICT1, typename ICT2>
lcm : mpl::integral_c<uintmax_t,
            static_lcm<
                XXX::abs<ICT1>::value,
                XXX::abs<ICT1>::value
>
> {};
}

Should these metafunctions be added to the 'mpl' namespace? if not what could be the a good name for XXX?

Best,
Vicente


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