Dst[] holding the converted elements.convertTo
size_t convertTo(Dst, R)(auto ref R src, Dst[] dst) if (isDstElem!Dst && isInputRange!R && !is(Unqual!R == var)
&& !is(R : string) && !is(R : wstring) && !is(R : dstring)
&& isSupportedSrcElem!(SrcElem!R))Converts a source range of supported elements into a fresh Dst[].
The result is always a new array, even when the element types match; exact zero-copy extraction of a matching native array is var.as!. Sources with a reliable length preallocate exactly; others grow amortized. Elements convert under the checked rules documented at module level.
Parameters
Dst | destination element type (numeric, string or var). |
R | source input range (native slices, var[], string[], Phobos ranges). Taken by auto ref: lvalues are consumed. |
Returns
Throws
VarException (with the failing element index) for rejected
conversions; range iteration errors propagate unchanged.
Example:
import std.algorithm.iteration: filter, map;
int[] narrow = [1, 2, 3, 4];
auto evens = narrow.filter!(x => x % 2 == 0).map!(x => x * 10)
.convertTo!long; // [20, 40]auto convertTo(Dst)(const var src) if (isDstElem!Dst)Converts an array-valued var (native array or boxed ARRAY) into a fresh Dst[].
Native arrays dispatch through visit to their typed element slices — no whole-array boxing, no per-element boxing on the typed path. Boxed ARRAYs convert their elements under the documented var rules. Non-array values throw VarTypeException.
Parameters
Dst | destination element type (numeric, string or var). |
src | the array-valued source (copied shallowly; not consumed). |
Returns
Dst[] with the converted elements.Throws
VarTypeException for non-array values; VarException (with the
failing element index) for rejected element conversions.
size_t convertTo(Dst)(const var src, Dst[] dst) if (isDstElem!Dst)Converts an array-valued var into a caller-provided buffer.
Same element semantics as the allocating adapter; capacity is checked before each write and exhaustion throws (never truncates silently).
Parameters
Dst | destination element type. |
src | the array-valued source (not consumed). |
dst | destination buffer, filled from index 0. |
Returns
Throws
VarTypeException for non-array values; VarException for rejected
elements or exhausted capacity.