Initialising a class with a native datatype necessary for GMP
0ffh
frank at frankhirsch.youknow.what.todo.net
Tue Nov 27 03:33:39 PST 2007
Matthias Walter wrote:
> In this post I will try to explain a problem, which I encountered in my
> GMP implementation. There are different approaches, how one may
> implement GMP, but the main goal here is that GMP numbers (mpz, mpq, mpf
> for integer, rational, floating point) can be used like normal ints and
> floats!
>
> Especially, the following things should work (with T any of those
> types):
>
> | T func (T a, T b = 0)
In case if T is a class, I'd suggest
T func (T a, T b = null)
{
if (b is null)
b=new b(defaultvalue);
...
}
In case if T is a struct, I'd suggest
const T uninit={foo:0 ... };
T func (T a, T b = uninit)
{
if (b==uninit)
b={ ... };
...
}
I know they're not perfect, but I wanted to suggest 'em anyway. =)
regards, frank
More information about the Digitalmars-d
mailing list