|
Boost : |
Subject: Re: [boost] [constrained_value] Constrained Value review results
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-10-08 14:52:08
----- Original Message -----
From: "Robert Kawulak" <robert.kawulak_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, October 08, 2010 7:45 PM
Subject: Re: [boost] [constrained_value] Constrained Value review results
2010/10/8 vicente.botet <vicente.botet_at_[hidden]>:
> I was wondering if we could not use Boost.Ratio to specify compile time bounds for boost::rational. So instead of
>
> bounded<rational, quarter2type, half2type>::type my_rational(rational(1, 2));
>
> we can do
>
> static_bounded<rational, ratio<1,4>, ratio<1,2> >::type my_rational(rational(1, 2));
Not static_bounded, but rather bounded<rational, ratio<1,4>, ratio<1,2> >::type.
ratio<1,4> is a type, not a compile time constant.
Once again I'll try to explain static_bounded (bounded_int,
bounded_ct or whatever we call it) is not exactly for bounds fixed at
compile time, but for bounds values of which can be expressed by
compile time constants.
> We can consider that ratio is the rational_constant of rational as integral_constant is the tpe constant for integral types. Of cousre, we will need to use a comparator that would be able to compare ratio and rational.
>
> template <intmax_t N, intmax_t D>
> bool operator<(rational<intmax_t> const& lhs, ratio<N,D> rhs);
> template <intmax_t N, intmax_t D>
> bool operator<(ratio<N,D> lhs, rational<intmax_t> const& rhs);
Or even simpler make ratio implicitly convertible to rational.
Either way, the best place for this functionality is probably the
rational class.
Best regards,
Robert
_______________________________________________
Sorr bau I dont see the difference. I consider ratio<N,D> to express a compile time constant through a type, as integral_c or integral_constant do.
If ratio is converible to rational, all the optimizations oportunities could be lost as we will compare two run time types.
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk