Specifying precision in vector<mpf_class>?

Ballabio Gerardo - Dip. di Scienza dei Materiali gerardo.ballabio@unimib.it
Wed, 16 Jul 2003 10:29:05 +0200

On 2003.07.16 01:46, Kevin Ryde wrote:
> "Felix E. Klee" <felix.klee.gmp@gmx.net> writes:
> what's the easiest way to create a std::vector of mpf_class with a 
> certain precision PREC (which is not the default precision)?

It's very easy, the constructor:

   template <class T>
   std::vector<T>::vector(size_type n, const T &value);

creates a std::vector<T> with n elements, each of which is a copy of 
value. Thus, to have a vector of mpf_class with precision PREC, just 

   std::vector v(n, mpf_class(0, PREC));

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