From 7d1b0891bb7fe7a23b4f27bb7039013e5304f894 Mon Sep 17 00:00:00 2001 From: Jack Applegame Date: Sun, 23 Jul 2017 15:18:59 +0300 Subject: [PATCH 1/3] formattedWrite should take output range by reference At the moment formattedWrite takes output range by value. It prevents to pass non-copyable ranges. --- std/format.d | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/std/format.d b/std/format.d index 10adbf24b42..d467bad7897 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...)(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...)(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)(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)(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)(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,7 @@ 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 +2120,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)(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 +2344,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)(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 +2400,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)(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 +2447,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)(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 +2520,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)(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 +2598,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)(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 +2641,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)(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 +3024,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 +3062,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)(ref Writer w, T val, const ref FormatSpec!Char f) if (is(StringTypeOf!T) && !is(T == enum)) { import std.array : appender; @@ -3147,7 +3147,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)(ref Writer w, T val, const ref FormatSpec!Char f) if (is(CharTypeOf!T) && !is(T == enum)) { if (f.spec == 's') @@ -3173,7 +3173,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)(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 +3188,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)(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 +3433,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)(ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == class) && !is(T == enum)) { enforceValidFormatSpec!(T, Char)(f); @@ -3582,7 +3582,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)(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 +3662,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)(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 +3797,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)(ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == enum)) { if (f.spec == 's') @@ -3866,7 +3866,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)(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 +3971,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)(ref Writer w, scope T, const ref FormatSpec!Char f) if (isDelegate!T) { formatValue(w, T.stringof, f); From 6995c19d61c54fc360b0c76c37aa82c6fb7c8ce8 Mon Sep 17 00:00:00 2001 From: Jack Applegame Date: Sun, 23 Jul 2017 15:27:05 +0300 Subject: [PATCH 2/3] Change "ref" to "auto ref" --- std/format.d | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/std/format.d b/std/format.d index d467bad7897..87c70747bdd 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...)(ref 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...)(ref 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; @@ -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)(ref 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)(ref 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)(ref 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)(ref Writer w, const(T) val, const ref FormatSpec!Char fs, +private void formatIntegral(Writer, T, Char)(auto ref Writer w, const(T) val, const ref FormatSpec!Char fs, uint base, ulong mask) { T arg = val; @@ -1918,7 +1918,7 @@ private void formatIntegral(Writer, T, Char)(ref Writer w, const(T) val, const r formatUnsigned(w, (cast(ulong) arg) & mask, fs, base, negative); } -private void formatUnsigned(Writer, T, Char)(ref Writer w, T arg, const ref FormatSpec!Char fs, uint base, bool negative) +private void formatUnsigned(Writer, T, Char)(auto ref Writer w, T arg, const ref FormatSpec!Char fs, uint base, bool negative) { /* Write string: * leftpad prefix1 prefix2 zerofill digits rightpad @@ -2120,7 +2120,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2344,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2400,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2447,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2520,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2598,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +2641,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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[]))) @@ -2855,7 +2855,7 @@ if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) && !hasToS } // input range formatting -private void formatRange(Writer, T, Char)(ref Writer w, ref T val, const ref FormatSpec!Char f) +private void formatRange(Writer, T, Char)(auto ref Writer w, ref T val, const ref FormatSpec!Char f) if (isInputRange!T) { import std.conv : text; @@ -3024,7 +3024,7 @@ if (isInputRange!T) } // character formatting with ecaping -private void formatChar(Writer)(ref Writer w, in dchar c, in char quote) +private void formatChar(Writer)(auto ref Writer w, in dchar c, in char quote) { import std.uni : isGraphical; @@ -3062,7 +3062,7 @@ private void formatChar(Writer)(ref 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)(ref 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 +3147,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)(ref 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 +3173,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)(ref 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 +3188,7 @@ Params: obj = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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; @@ -3332,7 +3332,7 @@ template hasToString(T, Char) } // object formatting with toString -private void formatObject(Writer, T, Char)(ref Writer w, ref T val, const ref FormatSpec!Char f) +private void formatObject(Writer, T, Char)(auto ref Writer w, ref T val, const ref FormatSpec!Char f) if (hasToString!(T, Char)) { static if (is(typeof(val.toString((const(char)[] s){}, f)))) @@ -3433,7 +3433,7 @@ const string toString(); Otherwise, are formatted just as their type name. */ -void formatValue(Writer, T, Char)(ref 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 +3582,7 @@ if (is(T == class) && !is(T == enum)) } /// ditto -void formatValue(Writer, T, Char)(ref 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 +3662,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)(ref 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 +3797,7 @@ Params: val = The value to write. f = The $(D FormatSpec) defining how to write the value. */ -void formatValue(Writer, T, Char)(ref 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 +3866,7 @@ if (is(T == enum)) /** Pointers are formatted as hex integers. */ -void formatValue(Writer, T, Char)(ref 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 +3971,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) /** Delegates are formatted by 'ReturnType delegate(Parameters) FunctionAttributes' */ -void formatValue(Writer, T, Char)(ref 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); From d2a3d8ae71b5643f1ae0fa0adcdf7e7e9c843c38 Mon Sep 17 00:00:00 2001 From: Jack Applegame Date: Sun, 23 Jul 2017 16:02:18 +0300 Subject: [PATCH 3/3] Remove unnecessary auto refs and fix style. --- std/format.d | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/std/format.d b/std/format.d index 87c70747bdd..cd6b82ceac8 100644 --- a/std/format.d +++ b/std/format.d @@ -1900,7 +1900,7 @@ if (is(IntegralTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) assert(w.data == "1337"); } -private void formatIntegral(Writer, T, Char)(auto ref 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)(auto ref Writer w, const(T) val, co formatUnsigned(w, (cast(ulong) arg) & mask, fs, base, negative); } -private void formatUnsigned(Writer, T, Char)(auto ref 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 @@ -2855,7 +2856,7 @@ if (is(DynamicArrayTypeOf!T) && !is(StringTypeOf!T) && !is(T == enum) && !hasToS } // input range formatting -private void formatRange(Writer, T, Char)(auto ref Writer w, ref T val, const ref FormatSpec!Char f) +private void formatRange(Writer, T, Char)(ref Writer w, ref T val, const ref FormatSpec!Char f) if (isInputRange!T) { import std.conv : text; @@ -3024,7 +3025,7 @@ if (isInputRange!T) } // character formatting with ecaping -private void formatChar(Writer)(auto ref 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; @@ -3332,7 +3333,7 @@ template hasToString(T, Char) } // object formatting with toString -private void formatObject(Writer, T, Char)(auto ref Writer w, ref T val, const ref FormatSpec!Char f) +private void formatObject(Writer, T, Char)(ref Writer w, ref T val, const ref FormatSpec!Char f) if (hasToString!(T, Char)) { static if (is(typeof(val.toString((const(char)[] s){}, f))))