http://d.puremagic.com/issues/show_bug.cgi?id=5233
--- Comment #2 from Rob Jacques <sandf...@jhu.edu> 2010-11-18 13:23:19 PST --- *sigh* Patch version 3. Added support for putting an input range into an output range. Unit test: assert( isOutputRange(Appender!(ubyte[]),string) ); Patch: void put(R, E)(ref R r, E e) { // BUG, adding template constraints result in a recursive expansion with isOutputRange static if ( __traits(compiles, {return R.init.put(E.init);}) ) { // Patch from Issue 4880 // commit to using the "put" method static if (!isArray!R && is(typeof(r.put(e)))) { r.put(e); } else static if (!isArray!R && is(typeof(r.put((&e)[0..1])))) { r.put((&e)[0..1]); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } else { static if (isInputRange!R) { // Commit to using assignment to front static if (is(typeof(r.front = e, r.popFront()))) { r.front = e; r.popFront(); } else static if (isInputRange!E && is(typeof(put(r, e.front)))) { for (; !e.empty; e.popFront()) put(r, e.front); } else static if( isSomeString!R && isSomeChar!E ) { static if( (typeof(r[0])).sizeof < E.sizeof ) { // must do some transcoding around here to support char[].put(dchar) Unqual!(typeof(r[0]))[(typeof(r[0])).sizeof == 1 ? 4 : 2] encoded; auto len = std.utf.encode(encoded, e); writeln( typeof(encoded).stringof,"\t", typeof(r[0]).sizeof ,"\t", E.sizeof ); foreach(c;encoded[0 .. len]) { r[0] = c; r.popFront; } } else { r[0] = e; r.popFront; } } else static if(hasSlicing!E && is(typeof(e.length == size_t)) && is(typeof(put(r, e[0]))) ) { for (; !e.empty; e = e[1..e.length]) put(r, e[0]); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } else { // Commit to using opCall static if (is(typeof(r(e)))) { r(e); } else static if (is(typeof(r((&e)[0..1])))) { r((&e)[0..1]); } else static if (isInputRange!E && is(typeof(put(r, e.front)))) { for (; !e.empty; e.popFront()) put(r, e.front); } else static if(hasSlicing!E && is(typeof(e.length == size_t)) && is(typeof(put(r, e[0]))) ) { for (; !e.empty; e = e[1..e.length]) put(r, e[0]); } else { static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof); } } } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------