digitalmars.D.learn - formattedWrite writes nothing
- ref2401 (22/22) May 02 2014 class MyClass {
- Andrej Mitrovic via Digitalmars-d-learn (9/14) May 02 2014 Ouch, ouch, ouch! What's happening is that the 'clear' Appender method
- anonymous (4/14) May 02 2014 I'd say clear should be @disabled in Appender for non-mutable
- Jared Miller (3/4) May 02 2014 I logged this bug a while ago:
class MyClass { Appender!string _stringBuilder; this() { _stringBuilder = Appender!string(null); _stringBuilder.clear(); } property string str() { return _stringBuilder.data; } void append(string s) { formattedWrite(_stringBuilder, "%s", s); } } MyClass c = new MyClass(); c.append("text 1"); c.append("__222"); writeln(c.str); //in this case nothing is printed out Following workarounds work: 1) call _stringBuilder.put() instead of formattedWrite() 2) if "_stringBuilder.clear()" is omitted in the constructor, formattedWrite(...) will work as expected. Is it a bug or is there a reason for such behaviour?
May 02 2014
On 5/2/14, ref2401 via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:class MyClass { Appender!string _stringBuilder; this() { _stringBuilder = Appender!string(null); _stringBuilder.clear();Ouch, ouch, ouch! What's happening is that the 'clear' Appender method is only compiled-in if the data is mutable, otherwise you end up calling the object.clear UFCS function. So don't use clear here. I don't know if this is a case of poor method naming or another downside of UFCS. Luckily 'clear' is being renamed to 'destroy' in the object module, so this specific case will not become a problem in the future.
May 02 2014
On Friday, 2 May 2014 at 10:23:03 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote:Ouch, ouch, ouch! What's happening is that the 'clear' Appender method is only compiled-in if the data is mutable, otherwise you end up calling the object.clear UFCS function. So don't use clear here. I don't know if this is a case of poor method naming or another downside of UFCS. Luckily 'clear' is being renamed to 'destroy' in the object module, so this specific case will not become a problem in the future.I'd say clear should be disabled in Appender for non-mutable data.
May 02 2014
I logged this bug a while ago: https://issues.dlang.org/show_bug.cgi?id=10291 On Friday, 2 May 2014 at 10:06:43 UTC, ref2401 wrote:Is it a bug or is there a reason for such behaviour?
May 02 2014