[committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases
Jonathan Wakely
jwakely@redhat.com
Fri Feb 28 23:08:00 GMT 2020
On 27/02/20 00:02 +0000, Jonathan Wakely wrote:
>On Wed, 26 Feb 2020 at 18:31, Daniel Krügler wrote:
>>
>> Am Mi., 26. Feb. 2020 um 16:20 Uhr schrieb Jonathan Wakely <jwakely@redhat.com>:
>> >
>> > This introduces a couple of convenience alias templates to be used for
>> > some repeated patterns using std::conditional_t.
>>
>> I find it a bit confusing/inconsistent to define __maybe_const_t such
>> that the bool argument says "is const", while for __maybe_empty_t the
>> corresponding bool argument says "is not empty". Suggestion: Implement
>> __maybe_empty_t such that its bool argument says "is empty" or change
>> the alias to __maybe_nonempty_t.
>
>Good point, I'll make that change. Thanks.
Here's what I'm proposing to change it to. The name "maybe present"
matches the relevant wording in the working draft, fixes the reversed
logic w.r.t the bool argument, and doesn't refer to the fact that the
type may be empty (which is not really the salient point about it).
While preparing this change it occurred to me that all types using
this alias might end up with a member of the same __detail::_Empty
type. If two such types would otherwise be at the same address, the
_Empty data member would force them to have different addresses. I
think in practice that's not an issue, because the only class template
that uses __maybe_present_t without any other data members is
_RangeAdaptor, and I don't think we need to care about users doing
something like:
struct Wtf : decltype(std::views::filter), decltype(std::views::take)
{ };
With the current code the two base classes can't have the same
address, because they each have a single data member of type
__detail::_Empty, which must have unique addresses.
It would be possible to implement those range adaptors so that the two
base subobjects could be at the same address, and so sizeof(Wtf) would
be smaller. I don't think I care about that.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 3858 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20200228/0316f408/attachment.bin>
More information about the Libstdc++
mailing list