convertTo

fnsize_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

Dstdestination element type (numeric, string or var).
Rsource input range (native slices, var[], string[], Phobos ranges). Taken by auto ref: lvalues are consumed.

Returns

A freshly allocated Dst[] holding the converted elements.

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]

fnauto 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

Dstdestination element type (numeric, string or var).
srcthe array-valued source (copied shallowly; not consumed).

Returns

A freshly allocated Dst[] with the converted elements.

Throws

VarTypeException for non-array values; VarException (with the

failing element index) for rejected element conversions.

fnsize_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

Dstdestination element type.
srcthe array-valued source (not consumed).
dstdestination buffer, filled from index 0.

Returns

The number of elements written.

Throws

VarTypeException for non-array values; VarException for rejected

elements or exhausted capacity.

fnauto convertTo(Dst, R)(auto ref R src) if (isDstElem!Dst && isInputRange!R && !is(Unqual!R == var) && !is(R : string) && !is(R : wstring) && !is(R : dstring) && isSupportedSrcElem!(SrcElem!R))
No documentation available for this declaration.