Date: Sat, 15 Feb 2020 21:14:19 -0800
On Sat, Feb 15, 2020 at 8:45 PM J Decker <d3ck0r_at_[hidden]> wrote:
>
>
> On Sat, Feb 15, 2020 at 8:40 PM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
> wrote:
>
>>
>> On Sat, Feb 15, 2020 at 11:10 PM J Decker <d3ck0r_at_[hidden]> wrote:
>>
>>> On Sat, Feb 15, 2020 at 7:07 PM Arthur O'Dwyer <
>>> arthur.j.odwyer_at_[hidden]> wrote:
>>>
>>>> Hi Jim,
>>>>
>>>> Sadly your idea doesn't work in C++, because C++ has *member functions*.
>>>> That is, we can write things like this:
>>>>
>>>> struct Widget {
>>>> void reset(); // reset the widget
>>>> };
>>>> [...]
>>>> std::unique_ptr<Widget> p = std::make_unique<Widget>();
>>>> p->reset(); // reset the pointed-to widget by calling Widget::reset()
>>>> member function
>>>> p.reset(); // reset the pointer's own value to nullptr
>>>>
>>>>
>>> But, isn't the .reset() implemented on the unique_ptr<> template as a
>>> operator. override? which takes precedence over the default behavior...
>>>
>>
>> No, C++ doesn't permit overloading the "." operator at all.
>> It's just that `p.reset()` calls `unique_ptr<Widget>::reset`,
>> and `p->reset()` calls `unique_ptr<Widget>::operator->` followed by
>> `Widget::reset`.
>>
>> I think you'll have to learn more about how C++ currently works, before
>> working on proposals to change it.
>>
>
> The cases that matter are all error cases now.
>
I can severely scope cut this, I do really only mean that, in the current
error condition where '.' is used and the left hand is a '*' pointer type,
that it can fallback to being like '->' and read the value of the pointer
instead of emitting an error.
In the first cut, GCC C it ended up being just as easy to say '->' is the
same as '.' but that was incidental, not by strict definition.
>
>>
>> –Arthur
>>
>
>
>
> On Sat, Feb 15, 2020 at 8:40 PM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
> wrote:
>
>>
>> On Sat, Feb 15, 2020 at 11:10 PM J Decker <d3ck0r_at_[hidden]> wrote:
>>
>>> On Sat, Feb 15, 2020 at 7:07 PM Arthur O'Dwyer <
>>> arthur.j.odwyer_at_[hidden]> wrote:
>>>
>>>> Hi Jim,
>>>>
>>>> Sadly your idea doesn't work in C++, because C++ has *member functions*.
>>>> That is, we can write things like this:
>>>>
>>>> struct Widget {
>>>> void reset(); // reset the widget
>>>> };
>>>> [...]
>>>> std::unique_ptr<Widget> p = std::make_unique<Widget>();
>>>> p->reset(); // reset the pointed-to widget by calling Widget::reset()
>>>> member function
>>>> p.reset(); // reset the pointer's own value to nullptr
>>>>
>>>>
>>> But, isn't the .reset() implemented on the unique_ptr<> template as a
>>> operator. override? which takes precedence over the default behavior...
>>>
>>
>> No, C++ doesn't permit overloading the "." operator at all.
>> It's just that `p.reset()` calls `unique_ptr<Widget>::reset`,
>> and `p->reset()` calls `unique_ptr<Widget>::operator->` followed by
>> `Widget::reset`.
>>
>> I think you'll have to learn more about how C++ currently works, before
>> working on proposals to change it.
>>
>
> The cases that matter are all error cases now.
>
I can severely scope cut this, I do really only mean that, in the current
error condition where '.' is used and the left hand is a '*' pointer type,
that it can fallback to being like '->' and read the value of the pointer
instead of emitting an error.
In the first cut, GCC C it ended up being just as easy to say '->' is the
same as '.' but that was incidental, not by strict definition.
>
>>
>> –Arthur
>>
>
Received on 2020-02-15 23:17:10