digitalmars.D.learn - C# code sample
- pragma (13/13) Jan 24 2011 Hi i come from a c# background
- Simen kjaeraas (10/24) Jan 24 2011 void foo( R )( R data )
- Jesse Phillips (2/32) Jan 24 2011 I thank it should be: is( ElementType!R == double[] ) )
- Simen kjaeraas (4/37) Jan 24 2011 True.
- Steven Schveighoffer (6/31) Jan 24 2011 Actually, isIterable would be more correct than isInputRange for this co...
- Mandeep Singh Brar (17/42) Jan 25 2011 Actually, isIterable would be more correct than isInputRange for this co...
- Jesse Phillips (2/16) Jan 25 2011 He is iterating over a range/iterable of double[], Simen got the type ch...
- Kagamin (2/17) Jan 26 2011 Usually there's a little need for a range in such case. IEnumerable is u...
- bearophile (4/5) Jan 26 2011 What do you mean? Do you mean regarding appends, iteration, or what?
- Jesse Phillips (2/7) Jan 26 2011 What? Of course there is a reason to use a Range/Iterable and has nothin...
I would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D? greetings
Jan 24 2011
pragma <the_ignorator hotmail.com> wrote:I would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D?void foo( R )( R data ) if ( isInputRange!R && is( ElementType!R == double ) ) { foreach ( d; data ) { do_some_stuff( d ); } } -- Simen
Jan 24 2011
Simen kjaeraas Wrote:pragma <the_ignorator hotmail.com> wrote:I thank it should be: is( ElementType!R == double[] ) )I would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D?void foo( R )( R data ) if ( isInputRange!R && is( ElementType!R == double ) ) { foreach ( d; data ) { do_some_stuff( d ); } } -- Simen
Jan 24 2011
Jesse Phillips <jessekphillips+D gmail.com> wrote:Simen kjaeraas Wrote:True. -- Simenpragma <the_ignorator hotmail.com> wrote:I thank it should be: is( ElementType!R == double[] ) )I would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it looklikein D?void foo( R )( R data ) if ( isInputRange!R && is( ElementType!R == double ) ) { foreach ( d; data ) { do_some_stuff( d ); } } -- Simen
Jan 24 2011
On Mon, 24 Jan 2011 14:39:33 -0500, Simen kjaeraas <simen.kjaras gmail.com> wrote:pragma <the_ignorator hotmail.com> wrote:Actually, isIterable would be more correct than isInputRange for this code example, not sure what the full code looks like. http://www.digitalmars.com/d/2.0/phobos/std_traits.html#isIterable -SteveI would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D?void foo( R )( R data ) if ( isInputRange!R && is( ElementType!R == double ) ) { foreach ( d; data ) { do_some_stuff( d ); } }
Jan 24 2011
On Mon, 24 Jan 2011 14:39:33 -0500, Simen kjaeraas <simen.kjaras gmail.com> wrote:pragma <the_ignorator hotmail.com> wrote:Actually, isIterable would be more correct than isInputRange for this code example, not sure what the full code looks like. http://www.digitalmars.com/d/2.0/phobos/std_traits.html#isIterable -Steve How about simply saying: void foo(double[] data) { foreach (d; data) { do_some_stuff(d); } } all ranges are already foreachable. Regards MandeepI would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D?void foo( R )( R data ) if ( isInputRange!R && is( ElementType!R == double ) ) { foreach ( d; data ) { do_some_stuff( d ); } }
Jan 25 2011
Mandeep Singh Brar Wrote:How about simply saying: void foo(double[] data) { foreach (d; data) { do_some_stuff(d); } } all ranges are already foreachable. Regards MandeepHe is iterating over a range/iterable of double[], Simen got the type check wrong, which I pointed out.
Jan 25 2011
pragma Wrote:I would like to write the following code in the according D style but i'm not sure howto do it void foo(IEnumerable<double[]> data) { foreach (var d in data) { do_some_stuff(d); } } i guess the D equivalent to IEnumerable is Range? how would it look like in D?Usually there's a little need for a range in such case. IEnumerable is usually used because there's a high need for the List collection so it's used even more often than arrays. Current druntime heap implementation already gives D arrays
Jan 26 2011
Kagamin:performance.What do you mean? Do you mean regarding appends, iteration, or what? Bye, bearophile
Jan 26 2011
Kagamin Wrote:pragma Wrote:What? Of course there is a reason to use a Range/Iterable and has nothing to do with performance. He could be getting his double[] from any number of functions found in std.algorithm, most of whom return their own Range type.i guess the D equivalent to IEnumerable is Range? how would it look like in D?Usually there's a little need for a range in such case. IEnumerable is usually used because there's a high need for the List collection so it's used even more often than arrays. Current druntime heap implementation already gives D arrays
Jan 26 2011