Purity, @safety, etc., in generic code
deadalnix
deadalnix at gmail.com
Wed Feb 20 21:20:36 PST 2013
On Thursday, 21 February 2013 at 04:07:46 UTC, Steven
Schveighoffer wrote:
> On Wed, 20 Feb 2013 21:50:01 -0500, deadalnix
> <deadalnix at gmail.com> wrote:
>
>> On Wednesday, 20 February 2013 at 13:42:48 UTC, Steven
>> Schveighoffer wrote:
>>> On Wed, 20 Feb 2013 01:00:00 -0500, deadalnix
>>> <deadalnix at gmail.com> wrote:
>>>
>>>> As discussed previously, I really wonder hy a const and non
>>>> const version of a function can exists in a first place.
>>>> What problem does it solve that isn't better solved by inout
>>>> ?
>>>
>>> const(T) and T are different types. Saying you can overload
>>> on types, unless they just vary by const is a special case
>>> that I don't think is worth adding.
>>>
>>
>> Explain me how the hell you overload on implicit parameter
>> types ?
>
> A method is simply a function that takes a hidden parameter of
> an object or struct.
>
> Really, a method with a signature Obj.foo() is a function with
> a signature foo(Obj this)
>
> A const method Obj.foo() const is a function with a signature
> foo(const(Obj) this)
>
> So it's equivalent to saying you can overload:
>
> foo(int *x)
> foo(const(int) *x)
>
> To disallow this would be unnecessarily restrictive.
>
That is called avoiding the question.
More information about the Digitalmars-d
mailing list