Boost logo

Boost :

Subject: Re: [boost] [constrained_value] Constrained Value review results
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-10-08 13:23:23

----- Original Message -----
From: "Robert Kawulak" <robert.kawulak_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, October 08, 2010 6:10 PM
Subject: Re: [boost] [constrained_value] Constrained Value review results

2010/10/8 Stewart, Robert <Robert.Stewart_at_[hidden]>:
>> You mean "bound" as past participle of "to bind", so "ct_bound" would
>> mean something that has been bound (i.e., "binded") at compile time? I
>> think the operation we want to express is bounding rather than
>> binding...
> I see the bounds as being applied at compile time, so it is bound to the specified range at compile time, so, yes, I meant the past participle of the infinitive "to bind." That the bounds continue to apply at runtime after having been bound at compile time is not, I think, the principle distinction.

But applying fixed bounds at compile time is not a defining
characteristic of "bounded_int", it is using compile time constant
expressions to specify the bounds.

>> > ct_bounded<int>
>> > rt_bounded<short>
>> The former is the subset of the latter, so "rt_bounded" is not a good
>> idea since it may represent objects with compile-time-fixed bounds as
>> well. I think just "bounded" is the best.
> Strictly speaking, runtime bounded is not a superset of compile time bounded, because one cannot choose to do either with the runtime bounded class, right?
> Thus, "bounded" is insufficient for the runtime version as that name implies both categories and does not clearly suggest the runtime variability.
> -1 "bounded"

I'm not trying to say that runtime bounded is a superset of compile
time bounded, but that "bounded" is a superset of "bounded_int". You
can use "bounded" with static or dynamic bounds. There are even cases
when "bounded_int" cannot be used to define static bounds and you have
to use "bounded" instead – these are all the cases where the bounds
cannot be expressed directly using compile time constant expressions,
e.g. for floats or rational numbers. See the example with rational
numbers in the second part of this subsection:

Best regards,


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));

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);

I don't know if there are applications that need this performance gain, but how knows.


Boost list run by bdawes at, gregod at, cpdaniel at, john at