diff --git a/std/format.d b/std/format.d index 10adbf24b42..cd6b82ceac8 100644 --- a/std/format.d +++ b/std/format.d @@ -438,7 +438,7 @@ My friends are "John", "Nancy". My friends are John, Nancy. ) */ -uint formattedWrite(alias fmt, Writer, A...)(Writer w, A args) +uint formattedWrite(alias fmt, Writer, A...)(auto ref Writer w, A args) if (isSomeString!(typeof(fmt))) { alias e = checkFormatException!(fmt, A); @@ -463,7 +463,7 @@ if (isSomeString!(typeof(fmt))) } /// ditto -uint formattedWrite(Writer, Char, A...)(Writer w, in Char[] fmt, A args) +uint formattedWrite(Writer, Char, A...)(auto ref Writer w, in Char[] fmt, A args) { import std.conv : text; @@ -1163,7 +1163,7 @@ if (is(Unqual!Char == Char)) trailing = fmt; } - bool writeUpToNextSpec(OutputRange)(OutputRange writer) + bool writeUpToNextSpec(OutputRange)(ref OutputRange writer) { if (trailing.empty) return false; @@ -1724,7 +1724,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(BooleanTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { BooleanTypeOf!T val = obj; @@ -1806,7 +1806,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(Unqual!T == typeof(null)) && !is(T == enum) && !hasToString!(T, Char)) { enforceFmt(f.spec == 's', @@ -1844,7 +1844,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(IntegralTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { alias U = IntegralTypeOf!T; @@ -1900,7 +1900,7 @@ if (is(IntegralTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) assert(w.data == "1337"); } -private void formatIntegral(Writer, T, Char)(Writer w, const(T) val, const ref FormatSpec!Char fs, +private void formatIntegral(Writer, T, Char)(ref Writer w, const(T) val, const ref FormatSpec!Char fs, uint base, ulong mask) { T arg = val; @@ -1918,7 +1918,8 @@ private void formatIntegral(Writer, T, Char)(Writer w, const(T) val, const ref F formatUnsigned(w, (cast(ulong) arg) & mask, fs, base, negative); } -private void formatUnsigned(Writer, T, Char)(Writer w, T arg, const ref FormatSpec!Char fs, uint base, bool negative) +private void formatUnsigned(Writer, T, Char) +(ref Writer w, T arg, const ref FormatSpec!Char fs, uint base, bool negative) { /* Write string: * leftpad prefix1 prefix2 zerofill digits rightpad @@ -2120,7 +2121,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { import std.algorithm.comparison : min; @@ -2344,7 +2345,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(Unqual!T : creal) && !is(T == enum) && !hasToString!(T, Char)) { immutable creal val = obj; @@ -2400,7 +2401,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(Unqual!T : ireal) && !is(T == enum) && !hasToString!(T, Char)) { immutable ireal val = obj; @@ -2447,7 +2448,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(CharTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { CharTypeOf!T val = obj; @@ -2520,7 +2521,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(StringTypeOf!T) && !is(StaticArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { Unqual!(StringTypeOf!T) val = obj; // for `alias this`, see bug5371 @@ -2598,7 +2599,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, auto ref T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, auto ref T obj, const ref FormatSpec!Char f) if (is(StaticArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { formatValue(w, obj[], f); @@ -2641,7 +2642,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { static if (is(const(ArrayTypeOf!T) == const(void[]))) @@ -3024,7 +3025,7 @@ if (isInputRange!T) } // character formatting with ecaping -private void formatChar(Writer)(Writer w, in dchar c, in char quote) +private void formatChar(Writer)(ref Writer w, in dchar c, in char quote) { import std.uni : isGraphical; @@ -3062,7 +3063,7 @@ private void formatChar(Writer)(Writer w, in dchar c, in char quote) // undocumented because of deprecation // string elements are formatted like UTF-8 string literals. -void formatElement(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatElement(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(StringTypeOf!T) && !is(T == enum)) { import std.array : appender; @@ -3147,7 +3148,7 @@ if (is(StringTypeOf!T) && !is(T == enum)) // undocumented because of deprecation // Character elements are formatted like UTF-8 character literals. -void formatElement(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatElement(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(CharTypeOf!T) && !is(T == enum)) { if (f.spec == 's') @@ -3173,7 +3174,7 @@ if (is(CharTypeOf!T) && !is(T == enum)) // undocumented // Maybe T is noncopyable struct, so receive it by 'auto ref'. -void formatElement(Writer, T, Char)(Writer w, auto ref T val, const ref FormatSpec!Char f) +void formatElement(Writer, T, Char)(auto ref Writer w, auto ref T val, const ref FormatSpec!Char f) if (!is(StringTypeOf!T) && !is(CharTypeOf!T) || is(T == enum)) { formatValue(w, val, f); @@ -3188,7 +3189,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T obj, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T obj, const ref FormatSpec!Char f) if (is(AssocArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) { AssocArrayTypeOf!T val = obj; @@ -3433,7 +3434,7 @@ const string toString(); Otherwise, are formatted just as their type name. */ -void formatValue(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == class) && !is(T == enum)) { enforceValidFormatSpec!(T, Char)(f); @@ -3582,7 +3583,7 @@ if (is(T == class) && !is(T == enum)) } /// ditto -void formatValue(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == interface) && (hasToString!(T, Char) || !is(BuiltinTypeOf!T)) && !is(T == enum)) { enforceValidFormatSpec!(T, Char)(f); @@ -3662,7 +3663,7 @@ if (is(T == interface) && (hasToString!(T, Char) || !is(BuiltinTypeOf!T)) && !is /// ditto // Maybe T is noncopyable struct, so receive it by 'auto ref'. -void formatValue(Writer, T, Char)(Writer w, auto ref T val, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, auto ref T val, const ref FormatSpec!Char f) if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !is(BuiltinTypeOf!T)) && !is(T == enum)) { enforceValidFormatSpec!(T, Char)(f); @@ -3797,7 +3798,7 @@ Params: val = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == enum)) { if (f.spec == 's') @@ -3866,7 +3867,7 @@ if (is(T == enum)) /** Pointers are formatted as hex integers. */ -void formatValue(Writer, T, Char)(Writer w, T val, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) { static if (isInputRange!T) @@ -3971,7 +3972,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) /** Delegates are formatted by 'ReturnType delegate(Parameters) FunctionAttributes' */ -void formatValue(Writer, T, Char)(Writer w, scope T, const ref FormatSpec!Char f) +void formatValue(Writer, T, Char)(auto ref Writer w, scope T, const ref FormatSpec!Char f) if (isDelegate!T) { formatValue(w, T.stringof, f);