Jump to page: 1 2
Thread overview
[Issue 1807] Wad3
[Issue 1807] ENHANCEMENT: Let IFTI "see through" templates to simple aliases
Apr 17, 2018
ag0aep6g
Apr 18, 2018
anonymous4
Oct 11, 2019
RazvanN
Dec 24, 2020
Walter Bright
Dec 24, 2020
Walter Bright
Sep 11, 2022
Modyhsh
[Issue 1807] ENHANCEMENT: Let IFTI "see through" templates to simple aliases
Sep 17, 2022
ag0aep6g
Oct 11, 2022
John Hall
Oct 11, 2022
John Hall
Dec 17, 2022
Iain Buclaw
Mar 22, 2023
FeepingCreature
Mar 23, 2023
kdevel
April 17, 2018
https://issues.dlang.org/show_bug.cgi?id=1807

--- Comment #7 from ag0aep6g <ag0aep6g@gmail.com> ---
*** Issue 10884 has been marked as a duplicate of this issue. ***

--
April 18, 2018
https://issues.dlang.org/show_bug.cgi?id=1807

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
           Hardware|x86                         |All
                 OS|Linux                       |All

--
October 11, 2019
https://issues.dlang.org/show_bug.cgi?id=1807

--- Comment #8 from RazvanN <razvan.nitu1305@gmail.com> ---
*** Issue 1942 has been marked as a duplicate of this issue. ***

--
December 24, 2020
https://issues.dlang.org/show_bug.cgi?id=1807

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=1653,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=1942,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=3904,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=7529,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=10884,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=16465,
                   |                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=16486

--
December 24, 2020
https://issues.dlang.org/show_bug.cgi?id=1807

--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> ---
Proposed DIP:

https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1023.md

Proposed Implementation:

https://github.com/dlang/dmd/pull/9778

--
September 11, 2022
https://issues.dlang.org/show_bug.cgi?id=1807

Modyhsh <dmm822@icloud.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmm822@icloud.com
            Summary|ENHANCEMENT: Let IFTI "see  |Wad3
                   |through" templates to       |
                   |simple aliases              |

--
September 17, 2022
https://issues.dlang.org/show_bug.cgi?id=1807

ag0aep6g <ag0aep6g@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com
            Summary|Wad3                        |ENHANCEMENT: Let IFTI "see
                   |                            |through" templates to
                   |                            |simple aliases

--
October 11, 2022
https://issues.dlang.org/show_bug.cgi?id=1807

John Hall <john.michael.hall@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.michael.hall@gmail.com

--- Comment #10 from John Hall <john.michael.hall@gmail.com> ---
(In reply to Walter Bright from comment #9)
> Proposed DIP:
> 
> https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1023.md
> 
> Proposed Implementation:
> 
> https://github.com/dlang/dmd/pull/9778

DIP 1023 has been postponed.

--
October 11, 2022
https://issues.dlang.org/show_bug.cgi?id=1807

--- Comment #11 from John Hall <john.michael.hall@gmail.com> ---
Creating a new type with an alias this'ed parameter is similar conceptually to a template alias. The new type is implicitly convertible to the target of the alias this and can be used wherever that original type was used. However, since it is a separate type, it can't called called where the alias is used.

```d
struct TemplateType(T) {}

//alias TemplateAlias(T) = TemplateType!T;
struct TemplateAlias(T) {
    TemplateType!T x;
    alias x this;
}

void templateFunction(T)(TemplateType!T arg) {}
void templateAliasFunction(T)(TemplateAlias!T arg) {}

void main()
{
    TemplateType!int inst;
    TemplateAlias!int ainst;

    templateFunction(inst);
    templateFunction(ainst);
    templateAliasFunction(inst); //doesn't compile
    templateAliasFunction(ainst);
}
```

Perhaps what is needed is some kind of mechanism like alias this...not in the sense of implicit conversion but in terms the programmer having the tools to tell the compiler what to do.

The idea would be that your template alias would include an additional template (with some rudimentary sketch below), call it `opResolveAlias`, that would let the compiler know the relationships going in reverse (so instead of from the alias to the alias target, this would be going from the alias target to the alias). The compiler could then make use of that information to make sure the function call can properly occur (with type inference as needed).

So for instance, if you have a function that accepts a `TemplateAlias!T` parameter, but pass in a `TemplateType!int` parameter, then currently the compiler doesn't look through the `TemplateAlias!T` to see that `TemplateType!int` is the same. However, if the compiler knows that a `TemplateType!int` is the same as `TemplateAlias!int`, then it would be better able to proceed.

```d
template TemplateAlias(T) {
    alias TemplateAlias = TemplateType!T;

    template opResolveAlias(alias U)
        if(is(U == TemplateType!V, V))
    {
        alias opResolveAlias = TemplateAlias!V;
    }
}
```

For simple cases like this, the compiler could generate its own `opResolveAlias`, but in the more general case it would be up to the user to provide it if it is important to them.

Issue 16486 has an example of a more complicated template alias [1] that should still be able to have this approach applied:

```d
template TestAlias(T)
{
    static if (is(T == float)) alias TestAlias = TestType!int;
    else alias TestAlias = string;

    // new part:
    template opResolveAlias(alias U)
    {
        static if (is(U == TestType!int)) {
            alias opResolveAlias = TestAlias!float;
        } else static if (is(U == string)) {
            alias opResolveAlias = TestAlias!int; //could put anything there
that's not float...not the most elegant
        }
    }
}
```

[1] https://issues.dlang.org/show_bug.cgi?id=16486#c1

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=1807

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--
« First   ‹ Prev
1 2