Construction From vector<char> ?

Robert Evans bobsphysics at yahoo.com
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.
Bob

 ----- Original Message ----

From: James Youngman <jay at gnu.org>
To: David Fang <fang at csl.cornell.edu>
Cc: gmp-discuss at swox.com; Robert Evans <bobsphysics at yahoo.com>
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 csl.cornell.edu> 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?

James.



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20080813/ee822950/attachment.html 


More information about the gmp-discuss mailing list