Skip to content

Implementing is_reference_v restraints? #2408

@cristeigabriela

Description

@cristeigabriela

Hello!

I was thinking, when trying to do the following (I know it isn't possible for clear specified reason, I was just tinkering):

std::allocator<char&> my_allocator;

we get good error input, but still not particularly the easiest to read. A way to make the output error better is with requires(!is_reference_v<_Ty>) after the template.

This will be particularly helpful when this is done with, say, std::vector, as the errors spewed are way more complicated than with allocator, obviously.

Here is what I mean, on msvc v19.latest:
https://godbolt.org/z/n5dE76na9

A situation where this could happen is when someone is trying to create a vector of a variable's type and that variable is a ref. It'd make reading the error to understand what's going on more easy. Perhaps this could even be turned into a static assert and get a message alongside.

You can comment the require constraint to see the difference.

From what I understood talking with others, this could classify as a "Quality of Implementation" enhancement. I tried to implement it but I can't think of a common denominator to reduce the amount of code and I do not want to litter and use up CI time, so I thought that a way to contribute without making things worse is to perhaps bring attention to this.

Kind regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions