www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - bigint implicit cast to bool breaks code

reply "Paul D. Anderson" <nobody hotmail.com> writes:
Issue 4120 added an implicit cast for BigInt to a boolean value.

This used to work:

/// Returns a mutable copy of a BigInt
public BigInt mutable(const BigInt num)
{
	BigInt big = cast(BigInt)num;
	return big;
}

But it now generates an error:

Error: template instance opCast!(BigInt) does not match template 
declaration opCast(T : bool)()

Is there another way to make a mutable copy of a BigInt?
May 30 2013
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Paul D. Anderson:

 Is there another way to make a mutable copy of a BigInt?

For now don't make bigints constant. const=>mutable cast is not a good idea in general, in D. Bye, bearophile
May 30 2013
prev sibling next sibling parent "Paul D. Anderson" <nobody hotmail.com> writes:
On Thursday, 30 May 2013 at 22:57:20 UTC, bearophile wrote:
 Paul D. Anderson:

 Is there another way to make a mutable copy of a BigInt?

For now don't make bigints constant. const=>mutable cast is not a good idea in general, in D. Bye, bearophile

It's like the old joke: "Doc, it hurts when I do this." Doctor: "Don't do that!" I need both constant and mutable BigInts. I don't want to convert a constant value to mutable, I just want a mutable copy. The cast was just a way to make a mutable copy but it's broken now. Other types have a .dup property which returns a mutable copy, but BigInt doesn't. Paul
May 30 2013
prev sibling next sibling parent "Paul D. Anderson" <nobody hotmail.com> writes:
On Thursday, 30 May 2013 at 22:32:08 UTC, Paul D. Anderson wrote:
 Issue 4120 added an implicit cast for BigInt to a boolean value.

 This used to work:

 /// Returns a mutable copy of a BigInt
 public BigInt mutable(const BigInt num)
 {
 	BigInt big = cast(BigInt)num;
 	return big;
 }

 But it now generates an error:

 Error: template instance opCast!(BigInt) does not match 
 template declaration opCast(T : bool)()

 Is there another way to make a mutable copy of a BigInt?

This doesn't work either, by the way: BigInt big = BigInt(num); Error: template std.bigint.BigInt._ctor does not match any function template declaration. Candidates are: ... std.bigint.BigInt.__ctor(T : const(char)[](T s) ... std.bigint.BigInt.__ctor(T x) if (isIntegral!(T))
May 30 2013
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Paul D. Anderson:

 It's like the old joke: "Doc, it hurts when I do this." Doctor: 
 "Don't do that!"

And it's a good advice because: - The mammalian body is able to heal a surprisingly high number of problems by itself, given the right conditions and enough time. In such time avoiding to do "that" (like jumping on a knee that hurts) is a good advice, and it's often one of the conditions for the healing. - Even if the body needs a bit of help from medicine, avoiding hurting a sore spot is often a good idea. Especially when there is no good cure available (like in many orthopaedic problems, that have surgery solutions that often cause more problems than the original problem).
 I need both constant and mutable BigInts.

Me too. In the last years I've put some bug reports on this in Bugzilla. Don is well aware that bigints are not const-corrected. It's a matter of working on them and fixing the problem, because maybe now D has all the tools to perform this fix/improvement. In the meantime my advice is to not use const bigints. Bye, bearophile
May 30 2013