C++ Logo

std-proposals

Advanced search

Re: is_deletable type traits

From: Zoe Carver <z.zoelec2_at_[hidden]>
Date: Sun, 2 Jun 2019 15:59:45 -0700
Thanks for the feedback, Arthur.

> but it does suggest that maybe you've got an XY problem
<http://xyproblem.info/> here.
This is not an XY problem. I came up with this trait because I had to
implement something similar in libc++ to fix an issue with overload
resolution. Your point about other unary operators in the standard library
is a good one. Maybe they too should be added.

> I would also caution that your proposal would make `is_deletable_v<int*>`
invariably true, even though not all `int*` values are in fact deletable.
I agree that this may be confusing to people.

> Do you have examples of
There is at least one (but probably several) place(s) in the standard
library where implementations must implement a trait like this. Here is an
example struct where "is_array_deletable" is true and the other false:

struct Foo
{
    void operator delete[] (void* ptr) { free(ptr); }
    void operator delete (void* ptr) = delete;
};

It should not be hard to imagine the opposite.

On Sun, Jun 2, 2019 at 11:08 AM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:

> On Sun, Jun 2, 2019 at 1:00 PM Zoe Carver via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> Before submitting a proposal for the following type traits, I wanted to
>> get the communities opinion. What are your thoughts on adding the following
>> to the standard library?
>>
>>
>> 1. is_deletable: if the expression "delete decltype<T>()" is well-formed, provides
>> the member constant value equal to true. Otherwise, value is false.
>>
>>
>> 2. is_array_deletable: if the expression "delete[] decltype<T>()" is
>> well-formed, provides the member constant value equal to true. Otherwise,
>> value is false.
>>
>>
>> This should be a small feature with little-no impact. I have a sample
>> implementation if that would be helpful.
>>
>
> Those names do look like the right names for that particular facility. But
> why do you want to add them to the standard library?
> I mean, the standard library doesn't have is_negatable<T>, or
> is_bitwise_negatable<T>, or has_sizeof<T>, or any of the other unary
> operators that I can think of. So why should `delete` be special-cased?
>
> I would also caution that your proposal would make `is_deletable_v<int*>`
> invariably true, even though not all `int*` values are in fact deletable.
> Deletability is a dynamic, runtime, property of a pointer value. This isn't
> a killer, but it does suggest that maybe you've got an XY problem
> <http://xyproblem.info> here. A new type-trait may not be the right tool
> for whatever underlying job you've actually got.
>
> Do you have examples of
> (A) generic-programming contexts where an `is_deletable` facility would
> have a beneficial effect?
> (B) examples of real-world code where `is_deletable_v<T> && not
> is_array_deletable_v<T>`, or vice versa?
> (C) examples of real-world code where `is_deletable_v<T> && not
> is_object_pointer_v<T>`, or vice versa?
>
> –Arthur
>

Received on 2019-06-02 18:01:43