Construction From vector<char> ?

James Youngman jay at gnu.org
Wed Aug 13 16:40:19 CEST 2008


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.


More information about the gmp-discuss mailing list