Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make properly @safe #12

Open
wilzbach opened this issue Feb 11, 2017 · 1 comment
Open

Make properly @safe #12

wilzbach opened this issue Feb 11, 2017 · 1 comment

Comments

@wilzbach
Copy link
Member

wilzbach commented Feb 11, 2017

Fix the holes in @trusted.

@wilzbach
Copy link
Member Author

wilzbach commented Feb 11, 2017

Biggest problem: Variant isn't @safe

struct SafeVariantN(size_t maxDataSize, AllowedTypesParam...)
{
    VariantN!(maxDataSize, AllowedTypesParam) _variant;
    alias _variant this;

    this(T)(T value) @trusted
    {
        static assert(_variant.allowed!(T), "Cannot store a " ~ T.stringof
            ~ " in a " ~ VariantN.stringof);
        _variant.opAssign(value);
    }

    ~this() @trusted {
        _variant.destroy();
    }

    this(this) @trusted {}

    SafeVariantN opAssign(T)(T rhs) @trusted
    {
        static if (!is(T == typeof(null)))
            _variant = _variant.opAssign(rhs._variant);
        return this;
    }
}

alias SafeVariant = SafeVariantN!(maxSize!(creal, char[], void delegate()));

...
    else static if (hasMember!(T, "_variant"))
    {
        static if (typeof(T.init._variant).stringof[0..8] == "VariantN")
            enum isVariantN = true;
        else
            enum isVariantN = false;
    }

...

import ddb.db : Variant = SafeVariant;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant