|
Boost : |
Subject: Re: [boost] [constrained_value] Constrained Value review results
From: Robert Kawulak (robert.kawulak_at_[hidden])
Date: 2010-10-08 13:45:53
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk