<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">The best way to do something like this is to create a pull request. This will not only give you credit for the change and make the code easy to add to Phobos, but it will make sure it doesn’t break any existing tests.<div class=""><br class=""></div><div class="">Please have a look here: <a href="http://wiki.dlang.org/Pull_Requests" class="">http://wiki.dlang.org/Pull_Requests</a></div><div class=""><br class=""></div><div class="">-Steve</div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 25, 2015, at 7:15 PM, Q. Schroll via phobos <<a href="mailto:phobos@puremagic.com" class="">phobos@puremagic.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">I'm new to this, maybe this proposal has been made once and I've overseen it.<br class=""><br class="">Tuples only allow the %s format specifier which is rather useless except from debugging.<br class=""><br class="">One way to format output a Tuple is expanding it. But this works only, when the tuple is outermost, i. e. like in format("%d: %.3f", int_float_tuple.expand), and not like in format("%(%d: %.3f%)", int_float_tuple_array.map!(t => t.expand)) which currently doesn't work.<br class=""><br class="">Therefore I propose to make Tuples also to be formated by %( %) and %( %| %).<br class="">For the first one, the expression inside is used to format the tuple the in the aforementioned way.<br class="">The second takes the tuple like an array (one expression and separators, not the escaping stuff).<br class=""><br class="">unittest<br class="">{<br class=""> import std.format : format;<br class=""> import std.typecons : Tuple, tuple;<br class=""> alias t = tuple;<br class=""> auto if_list = [ t(1, 1.0), t(2, 4.0), t(3, 9.0) ];<br class=""><br class=""> assert(format("%s", t("a", 1)) == `Tuple!(string, int)("a", 1)`);<br class=""> assert(format("%(%#x v %.4f w %#x%)", t(1, 1.0, 10)) == `0x1 v 1.0000 w 0xa`);<br class=""> assert(format("%(q%sq%| x %)", t("abc", 1, 2.3, [4,5])) == `qabcq x q1q x q2.3q x q[4, 5]q`);<br class=""> assert(format("%(%(%d^2 = %.1f%); %)", if_list) == `1^2 = 1.0; 2^2 = 4.0; 3^2 = 9.0`);<br class="">}<br class=""><br class="">Both can be done. I already have tested it and it works perfectly.<br class=""><br class="">All you have to do:<br class="">In typecons.d, line 762, add std.format.FormatSpec!char fmt = "%s" parameter.<br class="">In the function body, add at front<br class=""> if (fmt.nested)<br class=""> {<br class=""> if (fmt.sep)<br class=""> {<br class=""> foreach (i, Type; Types)<br class=""> {<br class=""> static if (i > 0)<br class=""> {<br class=""> sink(fmt.sep);<br class=""> }<br class=""> static if (is(Type == class) && is(typeof(Type.init) == shared))<br class=""> {<br class=""> sink(Type.stringof);<br class=""> }<br class=""> else<br class=""> {<br class=""> import std.format : format;<br class=""> sink(format(fmt.nested, field[i]));<br class=""> }<br class=""> }<br class=""> }<br class=""> else<br class=""> {<br class=""> import std.format : format;<br class=""> sink(format(fmt.nested, expand()));<br class=""> }<br class=""> return;<br class=""> }<br class="">The rest of the function can be left as it is.<br class=""><br class="">This feature cannot break any code I can imagine.<br class="">_______________________________________________<br class="">phobos mailing list<br class=""><a href="mailto:phobos@puremagic.com" class="">phobos@puremagic.com</a><br class="">http://lists.puremagic.com/mailman/listinfo/phobos</div></blockquote></div><br class=""></div></div></body></html>