D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8407 - Add inout inference to member functions in templates
Summary: Add inout inference to member functions in templates
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-21 17:28 UTC by Jonathan M Davis
Modified: 2024-12-13 18:00 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2012-07-21 17:28:36 UTC
In an attempt to make std.range.Cycle const-correct, I had to do stuff like this:

    @property auto ref front()
    {
        return _original[_index % _original.length];
    }

    static if (is(typeof((cast(const R)_original)[0])) &&
               is(typeof((cast(const R)_original).length)))
    {
        @property auto const ref front() const
        {
            return _original[_index % _original.length];
        }
    }

In the associated review,Aandrei mentioned the possibility of adding const inferrence to the list of attributes that are inferred for templated member functions. And I think that this code highlights the need for something along those lines.

However, given the fact that there are many cases where you want both a non-const function which returns a non-const result and const function which returns a const result (as is the case in the example above), I think that inout inferrence would be a better choice (though if the return type doesn't have to be const on a const function and inout doesn't work with that, then inferring const would be fine then).
Comment 1 Steven Schveighoffer 2015-01-08 12:48:44 UTC
A similar request came up in the forums. I think inferring const or inout would absolutely help quite a few cases where templates are used.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:00:41 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18454

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB