C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: [important] C++ Zero-Overhead exception proposal
From: Denis Kotov (redradist_at_[hidden])
Date: 2020-11-07 15:38:20


I think we as a community should look like eros done in Rust where it is
possible to return any object as value and they doing something to make it
behave as an exception from developer point of view ...

If Rust community can implement "exceptions"/errors zero-overhead and any
size, why can't we ?

On Wed, 4 Nov 2020 at 23:25, Denis Kotov <redradist_at_[hidden]> wrote:

> Are there any other thoughts on this mail list ?
>
> On Tue, 20 Oct 2020 at 11:35, Denis Kotov <redradist_at_[hidden]> wrote:
>
>> Also it would be useful to look how error handling do in Rust with Result
>> where Result<> is exactly the same idea that I suggest for C++
>> Result<> in Rust is union with additional value that say what is it -
>> result or error, and this union returned by value
>>
>> Nobody enforce users to use dynamic memory at all, instead user can use
>> dynamic memory directly to return pointer to data as error. It is provided
>> as option
>>
>> On Mon, 19 Oct 2020 at 23:40, Denis Kotov <redradist_at_[hidden]> wrote:
>>
>>> >> but returning large structs isn't exactly
>>> "zero-overhead" either
>>>
>>> Why ? Zero-overhead is all about if it is not possible to do better by
>>> hand ... And it is not possible to return better by hand !!
>>> With `exception_ptr` you enforce all to use dynamic memory management,
>>> but to return an object directly is more flexible because the user can
>>> return struct, it can return pointer to struct, it can return raw integer
>>> ... This solution more flexible for embedded as well as for general
>>> programming
>>>
>>> I just want in C++ Zero-overhead with ability to choose how exactly I
>>> want return error (by pointer or by value)
>>>
>>> On Mon, 19 Oct 2020 at 20:49, Jason McKesson via Std-Discussion <
>>> std-discussion_at_[hidden]> wrote:
>>>
>>>> FYI: You need to reply to the list to keep the discussion on the list.
>>>>
>>>> On Mon, Oct 19, 2020 at 3:49 AM Denis Kotov <redradist_at_[hidden]>
>>>> wrote:
>>>> >
>>>> > >> Being a "raw integer" is what gives us "zero overhead" (also,
>>>> > `std::error` is not a "raw integer"; it's two pointers in size)
>>>> >
>>>> > "Zero-overhead abstraction - don't pay for what you don't use, what
>>>> you use is as efficient as you can reasonably write by hand" from side of
>>>> Herb Sutter https://youtu.be/ARYP83yNAWk?t=328
>>>> > You cannot write more efficiently than that:
>>>> > ```cppunion SubscribeResult { Subscription res; SubscriptionError
>>>> err;
>>>> > };```
>>>> >
>>>> > Returning raw integer as error code is also "Zero-overhead", but it
>>>> is applied for some specific case ...
>>>> >
>>>> > What if with error you want to return data for this error ?
>>>> > It will become very hard to extend such an error system ..
>>>>
>>>> `std::error` as proposed by P0709 ***is not an integer***. It is a
>>>> specialized type that can store integer values, but it can also store
>>>> any data structure through an `exception_ptr`. Yes, they must be
>>>> dynamically-allocated, but returning large structs isn't exactly
>>>> "zero-overhead" either. This is especially true when throwing them.
>>>>
>>>> The functionality you want can already be done with the existing
>>>> P0709, just not in quite as convenient a way.
>>>> --
>>>> Std-Discussion mailing list
>>>> Std-Discussion_at_[hidden]
>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>>>
>>>
>>>
>>> --
>>>
>>> *Best RegardsDenis Kotov*
>>>
>>
>>
>> --
>>
>> *Best RegardsDenis Kotov*
>>
>
>
> --
>
> *Best RegardsDenis Kotov*
>

-- 
*Best RegardsDenis Kotov*


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups