[GSOC] Database API
Piotr Szturmaj
bncrbme at jadamspam.pl
Sat Mar 26 12:11:46 PDT 2011
Kagamin wrote:
> Christian Manning Wrote:
>
>> On 25/03/2011 14:56, Piotr Szturmaj wrote:
>>> To sum up, Phobos need some additional changes for database support,
>>> mainly addition of Nullable.
>>
>> For now, couldn't this just be included with the database module?
> Why not just use Variant? It should be able to hold anything, so Nullable should be not needed.
I think it should, for the same reason. Many times you want more
constrained data type than Variant. Say, some interface expect int or
null. Nullable!int is perfect for it. But if you use Variant, you may
end up having some struct inside or maybe some string, like 'abc' :)
In other words, base type of Nullable (for example int) is enforceable
at compile time, unlike Variant.
Anyway my probosal is compatible with Variant. Variant is an alias for
backend type VariantN. Quote from std.variant:
"VariantN is a back-end type seldom used directly by user code. Two
commonly-used types using VariantN as back-end are:
Algebraic: A closed discriminated union with a limited type universe
(e.g., Algebraic!(int, double, string) only accepts these three types
and rejects anything else).
Variant: An open discriminated union allowing an unbounded set of types.
The restriction is that the size of the stored type cannot be larger
than the largest built-in type. This means that Variant can accommodate
all primitive types and all user-defined types except for large structs.
Both Algebraic and Variant share VariantN's interface. (See their
respective documentations below.)"
I propose that, Nullable should be an alias (or subtype) of Algebraic,
for example:
template Nullable(T)
{
alias Algebraic!(T, void*) Nullable;
}
This way it will share the same backend as Variant, so both types will
be compatible.
More information about the Digitalmars-d
mailing list