digitalmars.D.learn - chaining chain Result and underlying object of chain
- Laeeth Isharc (4/4) Sep 14 2015 chain doesn't seem to compile if I try and chain a chain of two
- cym13 (2/6) Sep 14 2015 std.algorithm.iteration.joiner?
- John Colvin (2/6) Sep 14 2015 Works for me: http://dpaste.dzfl.pl/a692281f7a80
- anonymous (13/17) Sep 14 2015 Please show code, always.
- Laeeth Isharc (9/26) Sep 14 2015 Sorry - was exhausted yesterday when I had the code there, or
- anonymous (26/33) Sep 14 2015 Yes, the types don't match. The result types of most range functions dep...
- =?UTF-8?Q?Ali_=c3=87ehreli?= (14/19) Sep 14 2015 Exactly.
- John Colvin (3/24) Sep 14 2015 It is templated, but by means of it's enclosing function being
- Steven Schveighoffer (18/38) Sep 15 2015 typeid is a bit better:
chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead? Laeeth.
Sep 14 2015
On Monday, 14 September 2015 at 14:17:51 UTC, Laeeth Isharc wrote:chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead? Laeeth.std.algorithm.iteration.joiner?
Sep 14 2015
On Monday, 14 September 2015 at 14:17:51 UTC, Laeeth Isharc wrote:chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead? Laeeth.Works for me: http://dpaste.dzfl.pl/a692281f7a80
Sep 14 2015
On Monday 14 September 2015 16:17, Laeeth Isharc wrote:chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead?Please show code, always. A simple test works for me: ---- import std.algorithm: equal; import std.range: chain; void main() { auto chain1 = chain("foo", "bar"); auto chain2 = chain(chain1, "baz"); assert(equal(chain2, "foobarbaz")); } ----
Sep 14 2015
On Monday, 14 September 2015 at 14:31:33 UTC, anonymous wrote:On Monday 14 September 2015 16:17, Laeeth Isharc wrote:Sorry - was exhausted yesterday when I had the code there, or would have posted. I was trying to use the same variable eg auto chain1 = chain("foo", "bar"); chain1 = chain(chain1, "baz"); Realized that in this case it was much simpler just to use the delegate version of toString and sink (which I had forgotten about). But I wondered what to do in other cases. It may be that the type of chain1 and chain2 don't mix.chain doesn't seem to compile if I try and chain a chain of two strings and another string. what should I use instead?Please show code, always. A simple test works for me: ---- import std.algorithm: equal; import std.range: chain; void main() { auto chain1 = chain("foo", "bar"); auto chain2 = chain(chain1, "baz"); assert(equal(chain2, "foobarbaz")); } ----
Sep 14 2015
On Monday 14 September 2015 17:01, Laeeth Isharc wrote:auto chain1 = chain("foo", "bar"); chain1 = chain(chain1, "baz"); Realized that in this case it was much simpler just to use the delegate version of toString and sink (which I had forgotten about). But I wondered what to do in other cases. It may be that the type of chain1 and chain2 don't mix.Yes, the types don't match. The result types of most range functions depend on the argument types. Let's say chain("foo", "bar") has the type ChainResult!(string, string). Then chain(chain("foo", "bar"), "baz") has the type ChainResult! (ChainResult!(string, string), string). Those are different and not compatible. You can get the same type by: a) being eager: ---- import std.array: array; auto chain1 = chain("foo", "bar").array; chain1 = chain(chain1, "baz").array; ---- (At that point you could of course just work with the strings directly, using ~ and ~=.) b) being classy: ---- import std.range.interfaces; InputRange!dchar chain1 = inputRangeObject(chain("foo", "bar")); chain1 = inputRangeObject(chain(chain1, "baz")); ---- Those have performance implications, of course. Being eager means allocating the whole thing, and possibly intermediate results. Being classy means allocating objects for the ranges (could possibly put them on the stack), and it means indirections.
Sep 14 2015
On 09/14/2015 08:01 AM, Laeeth Isharc wrote:I was trying to use the same variable eg auto chain1 = chain("foo", "bar"); chain1 = chain(chain1, "baz");[...]It may be that the type of chain1 and chain2 don't mix.Exactly. I was going to recommend using pragma(msg, typeof(chain1)) to see what they are but it looks like chain()'s return type is not templatized. (?) pragma(msg, typeof(chain1)); pragma(msg, typeof(chain2)); Prints Result Result instead of something like (hypothetical) ChainResult!(string, string) ChainResult!(ChainResult!(string, string), string) Ali
Sep 14 2015
On Monday, 14 September 2015 at 15:30:14 UTC, Ali Çehreli wrote:On 09/14/2015 08:01 AM, Laeeth Isharc wrote:It is templated, but by means of it's enclosing function being templated, which doesn't end up in the name.I was trying to use the same variable eg auto chain1 = chain("foo", "bar"); chain1 = chain(chain1, "baz");[...]It may be that the type of chain1 and chain2 don't mix.Exactly. I was going to recommend using pragma(msg, typeof(chain1)) to see what they are but it looks like chain()'s return type is not templatized. (?) pragma(msg, typeof(chain1)); pragma(msg, typeof(chain2)); Prints Result Result instead of something like (hypothetical) ChainResult!(string, string) ChainResult!(ChainResult!(string, string), string) Ali
Sep 14 2015
On 9/14/15 11:30 AM, Ali Çehreli wrote:On 09/14/2015 08:01 AM, Laeeth Isharc wrote: > I was trying to use the same variable eg > > auto chain1 = chain("foo", "bar"); > chain1 = chain(chain1, "baz"); [...] > It may be that the type of chain1 > and chain2 don't mix. Exactly. I was going to recommend using pragma(msg, typeof(chain1)) to see what they are but it looks like chain()'s return type is not templatized. (?) pragma(msg, typeof(chain1)); pragma(msg, typeof(chain2)); Prints Result Result instead of something like (hypothetical) ChainResult!(string, string) ChainResult!(ChainResult!(string, string), string) Alitypeid is a bit better: import std.range; void main() { import std.stdio; auto chain1 = chain("hi", "there"); auto chain2 = chain(chain1, "friend"); writeln(typeid(chain1)); writeln(typeid(chain2)); } output: std.range.chain!(string, string).chain.Result std.range.chain!(Result, string).chain.Result I still see that "Result" as a parameter for chain2. I think the compiler should be better at printing these types at compile time. -Steve
Sep 15 2015