phobos icon indicating copy to clipboard operation
phobos copied to clipboard

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

Open shhreya13 opened this issue 8 months ago • 0 comments

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.

shhreya13 avatar Mar 10 '26 15:03 shhreya13