Specifying precision in vector<mpf_class>?
Felix E. Klee
felix.klee.gmp@gmx.net
Wed, 16 Jul 2003 11:13:51 +0200
On Wednesday 16 July 2003 10:49, Felix E. Klee wrote:
> > > If there's no easy way: Has someone considered adding the
> > > precision as a template parameter? That way one could write
> > > "std::vector<mpf_class<PREC> > some_vector".
> >
> > I did consider that when I started coding gmpxx.h, but at that time
> > g++ couldn't handle it (I guess it was g++ 2.91, or maybe g++ 2.8).
> > Current g++ probably can (I haven't tried), but I doubt that it would
> > be definitely better than how it is done now. (But if you can show me
> > why it's better, I'm willing to reconsider it.)
>
> As I wrote in my reply to Kevin's message, one could use template
> parameters to define new types like "very_long_double". Although I don't
> see any technical advantages over the current solution, this feature
> would IMHO make programs more readable.
I just found something that seems to be possible only with template
parameters:
mpf_class<PREC> x[100];
BTW, template parameters seem to be supported fine by newer versions of gcc.
The little program below compiles and executes fine with gcc 3.3 which is
part of my SuSE 8.2 installation:
#include <iostream>
using namespace std;
template<int prec> class a {
public:
void out() { cout << prec << endl; }
};
int main() {
a<3> x;
x.out();
return 0;
}
Felix
--
To contact me in private don't reply but send mail to
felix DOT klee AT inka DOT de