C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Requires-clause for data members

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 15 Feb 2024 12:56:58 +0100
It would be pretty chaotic if the member didn't exist entirely, not
even for the purpose of name lookup. This would also make it much more
difficult to write generic code because even if access was guarded by
if constexpr, the id-expression would already be ill-formed.

The solution with the least friction is to define it as a *removed
data member* if the requires-clause is not satisfied. It would still
have the same type as an *existing data member* so that decltype
works, but the removed data member would not correspond to any
subobject within an object of the surrounding class type.

So basically, it would be as if it was a zero-sized object with no
unique address. Any access (i.e. read or modify) would be ill-formed.
A class which contains only removed data members would be required
have the same layout as an empty class.

I heavily dislike if constexpr at class scope because scope has the
connotation that entities declared within are only available within
that scope, and this is not supposed to be the case for removed data
members.

Received on 2024-02-15 11:57:10