Thread overview
[Issue 23666] Recognize template opApply pattern
Feb 02, 2023
Bolpat
Feb 06, 2023
Bolpat
Feb 27, 2023
Iain Buclaw
Dec 12, 2023
Nick Treleaven
May 29
Bolpat
Jun 26
Dlang Bot
February 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23666

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--
February 06, 2023
https://issues.dlang.org/show_bug.cgi?id=23666

--- Comment #1 from Bolpat <qs.il.paperinik@gmail.com> ---
Generalization:

To be “aptly constrained” means that the constraint is a type of the following
form:
```d
Int delegate ParameterList MemberFunctionAttributes`
```
where `ParameterList` and `MemberFunctionAttributes` [3, 4] are defined in the
D grammar, and Int is `int` with any type constructors (`const`, `inout`,
`shared`) applied to it (they don’t matter anyways), but it shouldn’t fail
because some type inference made it e.g. `const`.

--
February 27, 2023
https://issues.dlang.org/show_bug.cgi?id=23666

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 12, 2023
https://issues.dlang.org/show_bug.cgi?id=23666

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #2 from Nick Treleaven <nick@geany.org> ---
You can use `auto opApply` to infer attributes instead of a template.

--
May 29
https://issues.dlang.org/show_bug.cgi?id=23666

--- Comment #3 from Bolpat <qs.il.paperinik@gmail.com> ---
(In reply to Nick Treleaven from comment #2)
> You can use `auto opApply` to infer attributes instead of a template.

```d
struct S
{
    auto opApply(int delegate(ref int) callback)
    {
        int x;
        return callback(x);
    }
}

void main() @safe
{
    foreach (ref x; S()) {} // Error: `@safe` function `D main` cannot call
`@system` function `S.opApply`
}
```

However, this does (for reasons beyond my understanding):
```d
struct S
{
    int opApplyImpl(DG : int delegate(ref int))(scope DG callback)
    {
        int x;
        return callback(x);
    }
    alias opApply = opApplyImpl!(int delegate(ref int));
}

void main() @safe
{
    foreach (ref x; S()) {}
}
```

--
May 31
https://issues.dlang.org/show_bug.cgi?id=23666

--- Comment #4 from Nick Treleaven <nick@geany.org> ---
Sorry, yes. This proposal seems workable.

--
June 26
https://issues.dlang.org/show_bug.cgi?id=23666

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@Bolpat created dlang/dlang.org pull request #3859 "Specify `opApply` as an alias to a function template instance" fixing this issue:

- Fix Bugzilla Issues 23666, 17953, 23116, and 24633

https://github.com/dlang/dlang.org/pull/3859

--