digitalmars.D.learn - is there a common type?
- =?ISO-8859-1?Q?Christian_K=F6stlin?= (3/3) May 15 2012 for [1, 2, 3] and iota(2, 10)?
- H. S. Teoh (8/9) May 15 2012 [...]
- =?ISO-8859-1?Q?Christian_K=F6stlin?= (11/16) May 17 2012 actually i just want to do some commandline parsing with default-values
- Simen Kjaeraas (11/31) May 17 2012 e:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (39/42) May 15 2012 When it comes to compile-time polymorphism or duck typing, they are both...
- =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= (4/46) May 17 2012 thanks a lot .. will try this.
for [1, 2, 3] and iota(2, 10)? thanks in advance christian
May 15 2012
On Tue, May 15, 2012 at 07:29:38PM +0200, Christian Köstlin wrote:for [1, 2, 3] and iota(2, 10)?[...] What are you trying to accomplish? T -- We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. -- Robert Wilensk
May 15 2012
On 5/15/12 19:44 , H. S. Teoh wrote:On Tue, May 15, 2012 at 07:29:38PM +0200, Christian Köstlin wrote:actually i just want to do some commandline parsing with default-values like this: int main(string[] args) { auto h = [1, 2, 3]; if (args.length > 1) { h = iota(1, args[1].to!(int)); } do_something_with(h); return 0; }for [1, 2, 3] and iota(2, 10)?[...] What are you trying to accomplish? T
May 17 2012
On Thu, 17 May 2012 16:28:56 +0200, Christian K=C3=B6stlin = <christian.koestlin gmail.com> wrote:On 5/15/12 19:44 , H. S. Teoh wrote:e:On Tue, May 15, 2012 at 07:29:38PM +0200, Christian K=C3=B6stlin wrot=s =actually i just want to do some commandline parsing with default-value=for [1, 2, 3] and iota(2, 10)?[...] What are you trying to accomplish? Tlike this: int main(string[] args) { auto h =3D [1, 2, 3]; if (args.length > 1) { h =3D iota(1, args[1].to!(int)); } do_something_with(h); return 0; }In that case, you should probably replace h =3D iota(1, args[1].to!(int)); with h =3D iota(1, args[1].to!(int)).array(); (assuming 2.059) or h =3D array(iota(1, args[1].to!(int)));
May 17 2012
On 05/15/2012 10:29 AM, Christian Köstlin wrote:for [1, 2, 3] and iota(2, 10)? thanks in advance christianWhen it comes to compile-time polymorphism or duck typing, they are both RandomAccessRanges. (Pedantically, [1, 2, 3] is not a range (I think :P), but a container. Although, any slice of it is a RandomAccessRange.) import std.range; import std.stdio; void foo(R)(R r) if (isRandomAccessRange!R) { if (!r.empty) { writeln(r[0]); } } void main() { foo([1, 2, 3]); foo(iota(2, 10)); } When it comes to runtime polymorphism, they can be both RandomAccessFinite!int: import std.range; import std.stdio; void foo(RandomAccessFinite!int r) { if (!r.empty) { writeln(r[0]); } } void main() { RandomAccessFinite!int r; r = inputRangeObject([1, 2, 3]); foo(r); r = inputRangeObject(iota(2, 10)); foo(r); } Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
May 15 2012
On 5/15/12 20:14 , Ali Çehreli wrote:On 05/15/2012 10:29 AM, Christian Köstlin wrote:thanks a lot .. will try this. regards christianfor [1, 2, 3] and iota(2, 10)? thanks in advance christianWhen it comes to compile-time polymorphism or duck typing, they are both RandomAccessRanges. (Pedantically, [1, 2, 3] is not a range (I think :P), but a container. Although, any slice of it is a RandomAccessRange.) import std.range; import std.stdio; void foo(R)(R r) if (isRandomAccessRange!R) { if (!r.empty) { writeln(r[0]); } } void main() { foo([1, 2, 3]); foo(iota(2, 10)); } When it comes to runtime polymorphism, they can be both RandomAccessFinite!int: import std.range; import std.stdio; void foo(RandomAccessFinite!int r) { if (!r.empty) { writeln(r[0]); } } void main() { RandomAccessFinite!int r; r = inputRangeObject([1, 2, 3]); foo(r); r = inputRangeObject(iota(2, 10)); foo(r); } Ali
May 17 2012