|
Boost Users : |
Subject: Re: [Boost-users] [integer_traits problem
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-05-29 19:33:58
Robert Ramey wrote:
> I'm having problems with integer traits when passed an __int64 type
> data type under Visual C++.
>
> I run the following test:
>
> boost::mpl::print<
> boost::mpl::integral_c<
> boost::intmax_t,
> boost::integer_traits<boost::intmax_t>::const_min
> >
>> x13;
> boost::mpl::print<
> boost::mpl::integral_c<
> boost::intmax_t,
> boost::integer_traits<boost::intmax_t>::const_max
> >
>> x8;
>
>
> What I expect to get for const_min is:
> ...
> 1> T=boost::mpl::integral_c<boost::intmax_t,0x8000000000000000>
> ...
>
>
> What I get is:
>
> 1>test_fixed_type.cpp
> 1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative
> integral constant converted to unsigned type
> 1> c:\projects\boost
> projects\safe_numerics\include\test_fixed_type.cpp(13)
>> see reference to class template instantiation 'boost::mpl::print<T>'
>> being
> compiled
> 1> with
> 1> [
> 1> T=boost::mpl::integral_c<boost::intmax_t,0x800000000>
> 1> ]
> 1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative
> integral constant converted to unsigned type
> 1> c:\projects\boost
> projects\safe_numerics\include\test_fixed_type.cpp(20)
>> see reference to class template instantiation 'boost::mpl::print<T>'
>> being
> compiled
> 1> with
> 1> [
> 1> T=boost::mpl::integral_c<boost::intmax_t,0x7fffffffffffffff>
> 1> ]
>
> That is the value for const_min is not correct !!. Note I've tried
> various different types such as using __int64 and also changed the
> rendering of he real vale to _I64_MIN. None of this seems to fix
> things.
> I've also tried making my own specialzation of integral_c for this
> type:
> template<boost::intmax_t C >
> struct integral_c<boost::intmax_t, C>
> {
> BOOST_STATIC_CONSTANT(boost::intmax_t, value = C);
> typedef integral_c_tag tag;
> typedef integral_c type;
> typedef boost::intmax_t value_type;
> operator boost::intmax_t() const { return this->value; }
> };
>
> Hmmm now I'm wondering about BOOST_STATIC_CONSTANT. and looking at the
> documenation of BOOST_STATIC_CONSTANT shows it's not really expected
> to work on anything wider than an int.
>
> What should one do in a case like this?
I just changed the specialization above to:
template<boost::intmax_t C >
struct integral_c<boost::intmax_t, C>
{
//BOOST_STATIC_CONSTANT(boost::intmax_t, value = C);
static const boost::intmax_t value = C;
typedef integral_c_tag tag;
typedef integral_c type;
typedef boost::intmax_t value_type;
operator boost::intmax_t() const { return this->value; }
};
and it didn't make any difference so I"m really stumped
>
> Robert Ramey
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net