www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10061] New: formattedRead should be more generic and accept output ranges

http://d.puremagic.com/issues/show_bug.cgi?id=10061

           Summary: formattedRead should be more generic and accept output
                    ranges
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu


--- Comment #0 from Martin Nowak <code dawg.eu> 2013-05-10 13:48:42 PDT ---
import std.format, std.range;

void main()
{
  string line = "12 13 14";

  // arrays work
  int[] ary;
  formattedRead(line, "%(%d %)", &ary);
  assert(ary == [12, 13, 14]);

  // output ranges
  auto app = appender!(int[])();
  formattedRead(line, "%(%d %)", &app);
  assert(app.data == [12, 13, 14]);

  // delegates
  int cnt = 12;
  auto dg = (int v) { assert(v == cnt++); };
  formattedRead(line, "%(%d %)", dg);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10 2013