Construction From vector<char> ?

Robert Evans bobsphysics at
Wed Aug 13 17:08:13 CEST 2008

Also very useful for me would be the output of an mpz_class object into an array (vector<char>).  Perhaps there is a way to do this via the ostream operators?  My basic problem is:  we are already using byte arrays which represent trans-64 bit numbers.  I could do a HUGE amount of refactoring of really bad code which manipulates such arrays if I could construct a mpz_class from such an array, do the arithmetic within GMP, output back into an array.   The C++ interface seems to character-based I/O only.
Thanks for any suggestions.

 ----- Original Message ----

From: James Youngman <jay at>
To: David Fang <fang at>
Cc: gmp-discuss at; Robert Evans <bobsphysics at>
Sent: Wednesday, August 13, 2008 9:40:19 AM
Subject: Re: Construction From vector<char> ?

On Wed, Aug 13, 2008 at 10:55 AM, David Fang <fang at> wrote:

> Hi all,
> Would anyone object to adding an iterator constructor (similar to
> std::string taking a pair of iterators)?  I'll just describe the idea below,
> I don't have time to provide a full patch at the moment.
> First, provide a generic interface function:
> /**
>        \param p pointer to mpz structure to set
>        \param b beginning of character sequence
>        \param e one-past-last character iterator (end)
>  */
> template <typename Iter>
> // inline
> int
> mpz_init_set_iter(mpz_ptr p, Iter b, Iter e) {
>        return __mpz_init_set_iter_dispatch(p,b,e,
>                typename std::iterator_traits<Iter>::iterator_category());
>        // dispatcher calls an efficient function for random-access
>        // iterators, such as char*, vector<char>::iterator,
>        // string::iterator, ...
>        // and some less efficient fallback routine for other iterators

Can't you just do that with a partial specialisation?


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the gmp-discuss mailing list