[committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

Jonathan Wakely-3
This introduces a couple of convenience alias templates to be used for
some repeated patterns using std::conditional_t.

        * include/std/ranges (__detail::__maybe_empty_t): Define new helper
        alias.
        (__detail::__maybe_const_t): Likewise.
        (__adaptor::_RangeAdaptor): Use __maybe_empty_t.
        (transform_view, take_view, take_while_view, elements_view): Use
        __maybe_const_t.
        (join_view, split_view): Use both.

Tested powerpc64l-linux, committed to master.


patch.txt (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

Daniel Krügler-3
Am Mi., 26. Feb. 2020 um 16:20 Uhr schrieb Jonathan Wakely <[hidden email]>:
>
> 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.

Thanks,

- Daniel
Reply | Threaded
Open this post in threaded view
|

Re: [committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

Jonathan Wakely-4
On Wed, 26 Feb 2020 at 18:31, Daniel Krügler wrote:

>
> Am Mi., 26. Feb. 2020 um 16:20 Uhr schrieb Jonathan Wakely <[hidden email]>:
> >
> > 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.
Reply | Threaded
Open this post in threaded view
|

Re: [committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

Pilar Latiesa
In reply to this post by Jonathan Wakely-3
> 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.

Would:
  template<bool _Present, typename _Tp, typename _Empty = decltype([]{})>
    using __maybe_present_t = std::conditional_t<_Present, _Tp, _Empty>;
work?

It appears to work, but I'm not sure this is allowed by [temp.res/8.5].
Reply | Threaded
Open this post in threaded view
|

Re: [committed] libstdc++: Add __maybe_const_t and __maybe_empty_t aliases

Jonathan Wakely-3
On 02/03/20 09:33 +0100, Pilar Latiesa wrote:

>> 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.
>
>Would:
>  template<bool _Present, typename _Tp, typename _Empty = decltype([]{})>
>    using __maybe_present_t = std::conditional_t<_Present, _Tp, _Empty>;
>work?
>
>It appears to work, but I'm not sure this is allowed by [temp.res/8.5].


Hmm, I'm not sure either, but I don't think I like it anyway :-)

I committed the patch that just renames it to __maybe_present_t. As I
said, I don't think the case of having two subobjects of the _Empty
type is likely in practice, and it wouldn't cause incorrect behaviour
anyway, just a small increase in size.