The template make in std.container.util could be improved in a few ways.
- 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);
- 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");
-
Improve the documentation of make to clarify that it abstracts the
difference between constructing structs (T(args)) and classes (new T(args)).
-
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.
The template
makein std.container.util could be improved in a few ways.std.algorithm.mutation.forwardwhen passingarguments 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);
static assertwhen theconstructor cannot be called with the provided arguments.
Example:
static assert(__traits(compiles, T(arguments)),
"Cannot construct "
T.stringof" with given arguments");Improve the documentation of
maketo clarify that it abstracts thedifference between constructing structs (
T(args)) and classes (new T(args)).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.