Re: Swap front for char[] input ranges

2016-12-21 Thread RazvanN via Digitalmars-d-learn
On Monday, 19 December 2016 at 20:26:26 UTC, Ali Çehreli wrote: On 12/19/2016 06:09 AM, RazvanN wrote: > [...] wrote: >> [...] InputRanges. >> [...] following > [...] char[] > [...] function, so > [...] http://dlang.org/phobos/std_algorithm_mutation.html#bringToFront [...] No need to mention i

Re: Swap front for char[] input ranges

2016-12-19 Thread Ali Çehreli via Digitalmars-d-learn
; swapping code >> > [...] >> >> Obivously, tmp1 and tmp2 are unusued there. :) >> >> > [...] >> passed. >> > [...] >> state >> > [...] >> is: >> > [...] >> input ranges >> > [...] >> >&

Re: Swap front for char[] input ranges

2016-12-19 Thread RazvanN via Digitalmars-d-learn
[...] passed. > [...] state > [...] is: > [...] input ranges > [...] Not possible... It's ok to use something similar to the following template constraint: void foo(R1, R2)(R1 r1, R2 r2) if ((hasSwappableElements!R1 && hasSwappableElements!R2) || (hasLvalueElements!R1 &&am

Re: Swap front for char[] input ranges

2016-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/19/2016 02:41 AM, RazvanN wrote: > Hi, > > I have a function which accepts 2 input Ranges As your comments make it clear below, they cannot be InputRanges. > and swaps the first > element in Range1 with the first element in Range2. The swapping code > looks s

Re: Swap front for char[] input ranges

2016-12-19 Thread Basile B. via Digitalmars-d-learn
On Monday, 19 December 2016 at 10:41:46 UTC, RazvanN wrote: Hi, I have a function which accepts 2 input Ranges and swaps the first element in Range1 with the first element in Range2. The swapping code looks something like this : static if (is(typeof(swap(r1.front, r2.front

Swap front for char[] input ranges

2016-12-19 Thread RazvanN via Digitalmars-d-learn
Hi, I have a function which accepts 2 input Ranges and swaps the first element in Range1 with the first element in Range2. The swapping code looks something like this : static if (is(typeof(swap(r1.front, r2.front { swap(r1.front, r2.front); } else

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-28 Thread Seb via Digitalmars-d-learn
On Saturday, 28 May 2016 at 20:43:00 UTC, pineapple wrote: On Saturday, 28 May 2016 at 16:25:02 UTC, Seb wrote: If you are interested how it works under the hood - it's pretty simple & elegant: I checked up on the phobos implementation and found that arrays are mutated when iterated over as r

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-28 Thread pineapple via Digitalmars-d-learn
On Saturday, 28 May 2016 at 16:25:02 UTC, Seb wrote: If you are interested how it works under the hood - it's pretty simple & elegant: I checked up on the phobos implementation and found that arrays are mutated when iterated over as ranges, which didn't rest well with me. Nor did the idea of

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-28 Thread Seb via Digitalmars-d-learn
On Friday, 27 May 2016 at 14:59:25 UTC, Adam D. Ruppe wrote: On Friday, 27 May 2016 at 14:54:30 UTC, pineapple wrote: I've encountered one remarkable difference: The phobos function accepts arrays and mine does not. add `import std.array;` i think to your module and it should make arrays rang

Re: I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 27 May 2016 at 14:54:30 UTC, pineapple wrote: I've encountered one remarkable difference: The phobos function accepts arrays and mine does not. add `import std.array;` i think to your module and it should make arrays ranges

I wrote a function that accepts input ranges, and I get compile errors when passing an array

2016-05-27 Thread pineapple via Digitalmars-d-learn
I'm writing my own map function modeled after the one in phobos. (because I feel like it, that's why. good learning experience.) I've encountered one remarkable difference: The phobos function accepts arrays and mine does not. I understand why - I'm calling methods that arrays don't have - but

Re: Input ranges

2015-04-20 Thread via Digitalmars-d-learn
On Sunday, 19 April 2015 at 23:49:08 UTC, anonymous wrote: On Sunday, 19 April 2015 at 21:42:23 UTC, Ulrich Küttler wrote: groupBy is a nice example as it laboriously adds reference semantics to forward ranges but assumes input ranges to posses reference semantics by themselves. All ranges

Re: Input ranges

2015-04-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 April 2015 at 21:42:23 UTC, Ulrich Küttler wrote: groupBy is a nice example as it laboriously adds reference semantics to forward ranges but assumes input ranges to posses reference semantics by themselves. All ranges are input ranges, though. Input ranges are the least

Re: Input ranges

2015-04-19 Thread via Digitalmars-d-learn
I am convinced most (all?) proper input ranges read input from an external source. (Reference semantic right there.) Input ranges are one-pass ranges after all. Therefore, reference semantics are required in any case (unless the use of the range is known beforehand.) groupBy is a nice example

Re: Input ranges

2015-04-19 Thread anonymous via Digitalmars-d-learn
On Saturday, 18 April 2015 at 22:01:56 UTC, Ulrich Küttler wrote: Input ranges from std.stdio are used for reading files. So assuming we create a file auto f = File("test.txt", "w"); f.writeln(iota(5).map!(a => repeat(to!string(a), 4)).joiner.joiner("\n&qu

Input ranges

2015-04-18 Thread via Digitalmars-d-learn
It seems input ranges without any indirection in memory are not working well with algorithms. This seems to be understood by the D community. I did not know. Here is my story on the topic so far: Recently, I learned that I did not know input ranges much at all, totally misjudging

Re: Using input ranges with std.regex?

2014-08-11 Thread MrSmith via Digitalmars-d-learn
On Wednesday, 25 April 2012 at 21:43:11 UTC, Dmitry Olshansky wrote: On 25.04.2012 23:08, H. S. Teoh wrote: Does std.regex support input ranges to match()? Or do I need to convert to string first? For now, yes you have to convert them. Any random access range of code units should do the

Re: Using input ranges with std.regex?

2012-04-25 Thread Dmitry Olshansky
On 25.04.2012 23:08, H. S. Teoh wrote: Does std.regex support input ranges to match()? Or do I need to convert to string first? For now, yes you have to convert them. Any random access range of code units should do the trick but stringish template constraints might kill that. I plan to

Using input ranges with std.regex?

2012-04-25 Thread H. S. Teoh
Does std.regex support input ranges to match()? Or do I need to convert to string first? Thanks! T -- Tell me and I forget. Teach me and I remember. Involve me and I understand. -- Benjamin Franklin