Re: using the full range of ubyte with iota

2015-01-25 Thread ketmar via Digitalmars-d-learn
On Sun, 25 Jan 2015 20:42:47 +, Dominikus Dittes Scherkl wrote: > But in a function you need the cast anyway: > ubyte swapNibbles(ubyte x) { return (x>>4) | (x>>4); } // compiler not > happy sure, it can't be happy, as `x` is promoted to int in the expression, so the expression result is `int

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 18:59:04 UTC, ketmar wrote: auto x2 = (x>>4) | (x<<4); // swap nibbles - but result in an int! this is true for C and C++ too, as all three languages doing "integer promotion". the only difference is that D forbids potentially lossy assigns. you best bet is

Re: using the full range of ubyte with iota

2015-01-25 Thread ketmar via Digitalmars-d-learn
On Sun, 25 Jan 2015 14:11:09 +, Dominikus Dittes Scherkl wrote: > On Sunday, 25 January 2015 at 13:03:16 UTC, bearophile wrote: >> Dominikus Dittes Scherkl: >> >>> Because this is useful in more situations, >> >> Right, but it's still a cast. And in D you want to minimize the number >> of usag

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 13:03:16 UTC, bearophile wrote: Dominikus Dittes Scherkl: Because this is useful in more situations, Right, but it's still a cast. And in D you want to minimize the number of usages of casts. The proposed syntax iota!"[]" is cast-safe. I don't case too much,

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 12:56:14 UTC, Tobias Pankrath wrote: On Sunday, 25 January 2015 at 12:25:35 UTC, Dominikus Dittes Scherkl wrote: map!(x => fn(cast(ParameterTypeTuple!fn[0])x) but instead with map!(paramCast!fn) Because this is useful in more situations, e.g. in every place whe

Re: using the full range of ubyte with iota

2015-01-25 Thread bearophile via Digitalmars-d-learn
Dominikus Dittes Scherkl: Because this is useful in more situations, Right, but it's still a cast. And in D you want to minimize the number of usages of casts. The proposed syntax iota!"[]" is cast-safe. Bye, bearophile

Re: using the full range of ubyte with iota

2015-01-25 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 25 January 2015 at 12:25:35 UTC, Dominikus Dittes Scherkl wrote: map!(x => fn(cast(ParameterTypeTuple!fn[0])x) but instead with map!(paramCast!fn) Because this is useful in more situations, e.g. in every place where you know the values would fit into the parameter (and for a sing

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 10:42:51 UTC, bearophile wrote: Vlad Levenfeld: What's this about !`[]` and std.range.uniform?? It's not in the documentation. It's an enhancement I have proposed. Hm. I had more something in mind like "paramCast" - a kind of big scissors that cut everything a

Re: using the full range of ubyte with iota

2015-01-25 Thread bearophile via Digitalmars-d-learn
Vlad Levenfeld: What's this about !`[]` and std.range.uniform?? It's not in the documentation. It's an enhancement I have proposed. Bye, bearophile

Re: using the full range of ubyte with iota

2015-01-24 Thread Vlad Levenfeld via Digitalmars-d-learn
you can always write your own iota replacement, which will do "[]" and use ubytes, for example. writing that things is way easier than in C++. something like "myIota!ubyte(0, 255)", for example -- to make it visible that it emits ubytes. I think closedInterval!T (T left, T right) would be a

Re: using the full range of ubyte with iota

2015-01-24 Thread ketmar via Digitalmars-d-learn
On Sun, 25 Jan 2015 00:12:18 +, Dominikus Dittes Scherkl wrote: > On Saturday, 24 January 2015 at 23:19:11 UTC, ketmar wrote: >> people that are new to D aren't used to D lambdas, so it's fairly >> common. > Oh, I am aware, but I didn't thought it would be necessary in this pace. > >> if you'

Re: using the full range of ubyte with iota

2015-01-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 24 January 2015 at 23:19:11 UTC, ketmar wrote: people that are new to D aren't used to D lambdas, so it's fairly common. Oh, I am aware, but I didn't thought it would be necessary in this pace. if you'll stay with D, you'll find yourself dreaming about such handy thing in another

Re: using the full range of ubyte with iota

2015-01-24 Thread ketmar via Digitalmars-d-learn
On Sat, 24 Jan 2015 22:57:57 +, Dominikus Dittes Scherkl wrote: > On Saturday, 24 January 2015 at 21:00:06 UTC, Tobias Pankrath wrote: >> On Saturday, 24 January 2015 at 20:49:03 UTC, Dominikus Dittes Scherkl >> wrote: >>> I would have no problem using an explicit cast, but where should I >>>

Re: using the full range of ubyte with iota

2015-01-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 24 January 2015 at 21:00:06 UTC, Tobias Pankrath wrote: On Saturday, 24 January 2015 at 20:49:03 UTC, Dominikus Dittes Scherkl wrote: I would have no problem using an explicit cast, but where should I apply it? iota(0, 256).map!(x => foo(cast(ubyte) x)) Ok, thank you very much.

Re: using the full range of ubyte with iota

2015-01-24 Thread ketmar via Digitalmars-d-learn
juicy question! signature.asc Description: PGP signature

Re: using the full range of ubyte with iota

2015-01-24 Thread ketmar via Digitalmars-d-learn
On Sat, 24 Jan 2015 20:49:01 +, Dominikus Dittes Scherkl wrote: > Maybe I'm just too stupid, but I cannot manage to call a simple function > with all 256 possible values of ubyte with iote: > > int foo(ubyte c); > > auto myRange = iota(0,256).map!foo; > > --> Error: function foo(ubyte c) i

Re: using the full range of ubyte with iota

2015-01-24 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 24 January 2015 at 20:49:03 UTC, Dominikus Dittes Scherkl wrote: Maybe I'm just too stupid, but I cannot manage to call a simple function with all 256 possible values of ubyte with iote: int foo(ubyte c); auto myRange = iota(0,256).map!foo; --> Error: function foo(ubyte c) is no

Re: using the full range of ubyte with iota

2015-01-24 Thread bearophile via Digitalmars-d-learn
Dominikus Dittes Scherkl: Has anyone any idea how to work around this? In Bugzilla I have proposed to solve this problem with this syntax taken from std.range.uniform: iota!"[]"(ubyte.min, ubyte.max) Bye, bearophile

Re: using the full range of ubyte with iota

2015-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 24, 2015 at 08:49:01PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: > Maybe I'm just too stupid, but I cannot manage to call a simple function > with all 256 possible values of ubyte with iote: > > int foo(ubyte c); > > auto myRange = iota(0,256).map!foo; [...] Try