GMP and C++11 move constructors

Marc Glisse marc.glisse at inria.fr
Wed May 23 20:30:07 UTC 2018


On Wed, 23 May 2018, Marco Bodrato wrote:

> From gmp-discuss:
>
> Il Lun, 21 Maggio 2018 12:15 pm, Marc Glisse ha scritto:
>> If m is a
>> moved-from object, it is fine to assign a new value to it with m =
>> whatever. That's even what std::swap does. It should also be fine to
>> read from it, although you can't rely on any specific value so that's
>> not very useful.
>
> Should the non specific value be somehow valid?

Preferably, though that's not really important, many types have a state 
where you can only destruct or assign a new value.

> With lazy allocation, we should define NaN as an admissible value for mpq,
> and use it whenever we init a variable that will immediately be
> overwritten.

Ah, as an implementation detail, not a public interface, this avoids a lot 
of trouble.

> I did this, internally in mini-mpq:
> https://gmplib.org/repo/gmp/rev/8e0a2e94ae5a
>
> The idea might be useful also for some mpq constructor from double, from
> string...

> if not for move.

Ah, I see where you are going now. That's an interesting idea.

> Wile we are looking into this, is there a motivation why we have the
> assignment "operator=(mpz_class &&z)" for mpq_class, but not a constructor
> from mpz_class&& ?

Hmm, I forgot to add one? ;-)

-- 
Marc Glisse


More information about the gmp-devel mailing list