 Boost :

Subject: Re: [boost] [Boost-users] [Review] ITL review starts today, February 18th
From: John Reid (j.reid_at_[hidden])
Date: 2010-03-04 09:29:55

Joachim Faulhaber wrote:
>> What is the meaning of the cardinality of a continuous interval? It seems to
>> be defined to be 0? Why not make it only available for discrete domains?
>
> Try this:
>
> interval<double> x(0.0, 1.0);
> if(x.cardinality() == numeric_limits<interval<double>::size_type>::infinity())
> cout << "cardinality is infinite\n";
>
> for doubles a, b with a < b:
> [a,b).cardinality() == infinity but
> {[a,a],[b,b]}.cardinality() == 2
>
> Function cardinality() has been introduced to make clear: This
> function yields the number of *elements*, and not the number of
> iteratable entities in the interval container. For continuous
> domain_types the cardinality of an interval container can be infinite
> but it can be finite as well.

This seems to make the cardinality of empty intervals infinite! I get
this output from the code below:

empty interval cardinality is 0
empty interval cardinality is infinite
unit interval cardinality is 0
unit interval cardinality is infinite
singleton interval cardinality is 1

{
const interval< double > empty_interval;
cout << "empty interval cardinality is " <<
empty_interval.cardinality() << "\n";
if( empty_interval.cardinality() == numeric_limits< interval< double
>::size_type >::infinity() )
cout << "empty interval cardinality is infinite\n";
}

{
const interval< double > unit_interval( 0.0, 1.0 );
cout << "unit interval cardinality is " << unit_interval.cardinality()
<< "\n";
if( unit_interval.cardinality() == numeric_limits< interval< double
>::size_type >::infinity() )
cout << "unit interval cardinality is infinite\n";
}

{
const interval< double > singleton_interval( 0.0 );
cout << "singleton interval cardinality is " <<
singleton_interval.cardinality() << "\n";
if( singleton_interval.cardinality() == numeric_limits< interval<
double >::size_type >::infinity() )
cout << "singleton interval cardinality is infinite\n";
}

Do you agree this is potentially confusing?