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

@disable new trick #141

Open
p0nce opened this issue Apr 9, 2018 · 0 comments
Open

@disable new trick #141

p0nce opened this issue Apr 9, 2018 · 0 comments

Comments

@p0nce
Copy link
Owner

p0nce commented Apr 9, 2018

By Basile, co-invented with Ketmar and Adam

/**
 * When mixed in a aggregate this template has for effect to disable the usage
 * the $(D new) operator.
 */
mixin template disableNew()
{
    @disable new (size_t){return null;}
}
///
unittest
{
    // class requiring users to use allocators.
    class NotUsableWithNew
    {
        mixin disableNew;
    }

    // statically verify that `new` cannot be used.
    static assert(!__traits(compiles, new NotUsableWithNew));
}
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