tail const
Steven Schveighoffer
schveiguy at yahoo.com
Thu Dec 2 13:14:58 PST 2010
On Thu, 02 Dec 2010 07:09:27 -0500, Michel Fortin
<michel.fortin at michelf.com> wrote:
> On 2010-12-02 05:57:18 -0500, Fawzi Mohamed <fawzi at gmx.ch> said:
>
>> well as your are at it I would argue a bit more on the syntax.
>> [...]
>> I suppose that will probably considered too difficult to implement,
>> but I wanted to propose it again because I find that it is the most
>> clean solution conceptually.
>
> It is significantly more complex, not only for the compiler but also for
> the one reading/writing the code, as you'd have to propagate that
> 'weak_const' as a new, distinct modifier for it to be usable across
> function calls. I don't think it's worth it really.
>
> As for the syntax for classes, I feel "const(Object)ref" with the
> optional ref marker is easier to grasp than introducing a new concept
> called 'weak_const'. I welcome any suggestions, but my aim is to keep
> the changes as small and localized as possible in the compiler and
> follow as closely as possible existing language patterns.
>
> My only concern with the "const(Object)ref" syntax is that we're reusing
> 'ref' to denote an object reference with different properties
> (rebindable, nullable) than what 'ref' currently stands for. But it
> remains the best syntax I've seen so far.
Where it would be beneficial is in mimicking the tail-const properties of
arrays in generic ranges.
I have a container C, which defines a range over its elements R.
const(R) is not a usable range, because popFront cannot be const. So now
I need to define constR, which is identical to R, except the front()
function returns a const element.
So now, I need the same for immutable.
And now I need to triplicate all my functions which accept the ranges, or
return them.
And I can't use inout(R) as a return value for ranges.
If you can solve the general problem, and not just the class tail-const,
it would be hugely beneficial.
My thought was that a modifier on const itself could be stored in the
TypeInfo_Const as a boolean (tail or not), and the equivalent done in dmd
source itself.
-Steve
More information about the Digitalmars-d
mailing list