Re: Defining an alias to an overloaded function

2020-01-23 Thread olvy via Digitalmars-d-learn

On Tuesday, 21 January 2020 at 04:44:43 UTC, Boris Carvajal wrote:

This seems to work:

...
struct RangeImpl(T) {
alias byKeyRetType = 
typeof(byKey!(int[T])((int[T]).init));

byKeyRetType keyRange;
this(ref int[T] d) {
keyRange = d.byKey;
}
bool empty() {
return keyRange.empty;
}
...
}

RangeImpl!T opSlice() {
return RangeImpl!T(_dict);
}
}

void main()
{
...
if (h[].all!(nn => nn < 5)) {
writeln("less than 5");
}


Thank you very much!  I have completely forgotten about typeof().

I see you also fixed my unnecessary (T) template parameter to 
opSlice, which also caused a compilation error in addition to the 
first mistake.  I think this is because it "shadows" the original 
T parameter from the struct itself, right?





Re: Defining an alias to an overloaded function

2020-01-20 Thread Boris Carvajal via Digitalmars-d-learn

On Monday, 20 January 2020 at 22:02:54 UTC, olvy wrote:
I'm learning D, and as an exercise, I'm trying to define a 
HashSet that would be a wrapper around an associative array 
with some dummy value type.


This seems to work:

...
struct RangeImpl(T) {
alias byKeyRetType = 
typeof(byKey!(int[T])((int[T]).init));

byKeyRetType keyRange;
this(ref int[T] d) {
keyRange = d.byKey;
}
bool empty() {
return keyRange.empty;
}
...
}

RangeImpl!T opSlice() {
return RangeImpl!T(_dict);
}
}

void main()
{
...
if (h[].all!(nn => nn < 5)) {
writeln("less than 5");
}