Skip to content

Improve std.container.util.make with forwarding and clearer compile-time errors #10972

Description

@shhreya13

The template make in std.container.util could be improved in a few ways.

  1. Preserve move semantics using std.algorithm.mutation.forward when passing
    arguments to constructors. Currently arguments are passed directly, which may
    cause unnecessary copies.

Current code:
return T(arguments);

Suggested improvement:
import std.algorithm.mutation : forward;
return T(forward!arguments);

  1. Improve compile-time diagnostics by adding a static assert when the
    constructor cannot be called with the provided arguments.

Example:
static assert(__traits(compiles, T(arguments)),
"Cannot construct "T.stringof" with given arguments");

  1. Improve the documentation of make to clarify that it abstracts the
    difference between constructing structs (T(args)) and classes (new T(args)).

  2. Add additional edge-case unit tests (e.g., empty container construction).

If this approach is acceptable, I would be happy to submit a PR implementing
these improvements.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions