Boost logo

Boost :

From: Joerg Walter (jhr.walter_at_[hidden])
Date: 2002-09-07 13:21:02


----- Original Message -----
From: "Gabriel Dos Reis" <gdr_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, September 07, 2002 5:28 PM
Subject: Re: [boost] Formal Review for Interval Library (was:
IntervalLibraryreminder)

> jhr.walter_at_[hidden] (Joerg Walter) writes:
>
> | Ok, but the fact remains, that such a general purpose class doesn't
behave
> | like the builtin data types and it should, IMHO. Would you really like
to
> | abolish type promotion?
>
> I'm not proposing to abolish type promotion. And I'm not promoting
> automatic type-promotion either.

Ok. To demonstrate the consequences for basic linear algebra, I wrote a
small sample:

#include <boost/interval.hpp>
#include <boost/interval/io.hpp>

#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

using std::complex;
using boost::interval;
using boost::numeric::ublas::vector;

int main() {
    double rs1 = 0;
    float rs2 = 0;
    std::cout << rs1 + rs2 << std::endl;

    complex<double> cs1 = 0;
    complex<float> cs2 = 0;
    // Doesn't work.
    // std::cout << cs1 + cs2 << std::endl;
    std::cout << cs1 + complex<double> (cs2) << std::endl;

    interval<double> ris1 = 0;
    interval<float> ris2 = 0;
    // Doesn't work.
    // std::cout << ris1 + ris2 << std::endl;
    // std::cout << ris1 + interval<double> (ris2) << std::endl;
    std::cout << ris1 + interval<double> (ris2.lower (), ris2.upper ()) <<
std::endl;

    // We won't start dreaming ;-)
    // complex<interval<double> > cis1 = 0;
    // complex<interval<float> > cis2 = 0;
    // std::cout << cis1 + complex<interval<double> > (cis2) << std::endl;

    vector<double> rv1 (1);
    vector<float> rv2 (1);
    rv1.clear ();
    rv2.clear ();
    std::cout << rv1 + rv2 << std::endl;

    vector<complex<double> > cv1 (1);
    vector<complex<float> > cv2 (1);
    cv1.clear ();
    cv2.clear ();
    // Doesn't work.
    // std::cout << cv1 + cv2 << std::endl;
    std::cout << cv1 + vector<complex<double> > (cv2) << std::endl;

    vector<interval<double> > riv1 (1);
    vector<interval<float> > riv2 (1);
    riv1.clear ();
    riv2.clear ();
    // Doesn't work.
    // std::cout << riv1 + riv2 << std::endl;
    // std::cout << riv1 + vector<interval<double> > (riv2) << std::endl;
    // And now?

    // This should be possible:
    // vector<complex<interval<double> > > civ1 (1);
    // vector<complex<interval<float> > > civ2 (1);
    // civ1.clear ();
    // civ2.clear ();
    // std::cout << civ1 + civ2 << std::endl;
}

Especially unpleasant is, that the temporary vectors, which were previously
eliminated through expression templates, resurrect. Sorry, I'm not happy
with this.

> | The only other way I see is, that standard library vendors document how
to
> | extend their implementations and boost supports one ore more different
> | extensions then.
>
> Yeah.

Do you already have a concrete idea, how this could work with GCC for
example?

Regards

Joerg


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk