C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow using type alias in requires-clause

From: Kang Hewill <hewillk_at_[hidden]>
Date: Thu, 17 Aug 2023 00:12:34 +0800
That's exactly what I thought! and this syntactic sugar does have
observable benefits.

I first came up with this idea when I implemented 'common_reference' [
https://eel.is/c++draft/meta#trans.other-2] a few years ago, and I found
that if such syntax is supported, the implementation of 'common_reference'
will become extremely intuitive and simple. Recently, I was looking at
P2542's definition of the concept of 'concatable' [
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2542r3.html#class-template-concat_view-range.concat.view],
which made me feel more necessary for the existence of this syntactic sugar.

Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> 於
2023年8月16日 週三 下午11:59寫道:

> On Wed, Aug 16, 2023 at 11:39 AM Kang Hewill via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Hello all C++ experts,
> >
> > I find it very convenient to allow using-type alias in the
> requires-clause.
> >
> > For complex type aliases, simplifying them with using-alias can reduce
> redundant spelling for subsequent constraint checks on the same type alias.
> >
> > Take the standard concept indirectly-readable-impl as an example:
> >
> > template<class In>
> > concept indirectly-readable-impl =
> > requires(const In in) {
> > typename iter_value_t<In>;
> > typename iter_reference_t<In>;
> > typename iter_rvalue_reference_t<In>;
> > { *in } -> same_as<iter_reference_t<In>>;
> > { ranges::iter_move(in) } -> same_as<iter_rvalue_reference_t<In>>;
> > } &&
> > common_reference_with<iter_reference_t<In>&&, iter_value_t<In>&> &&
> > common_reference_with<iter_reference_t<In>&&,
> iter_rvalue_reference_t<In>&&> &&
> > common_reference_with<iter_rvalue_reference_t<In>&&, const
> iter_value_t<In>&>;
> >
> > we can simplify it to:
> >
> > template<class In>
> > concept indirectly-readable-impl =
> > requires(const In in) {
> > using value_type = typename iter_value_t<In>;
> > using reference = typename iter_reference_t<In>;
> > using rvalue_reference = typename iter_rvalue_reference_t<In>;
> > { *in } -> same_as<reference>;
> > { ranges::iter_move(in) } -> same_as<rvalue_reference>;
> > requires common_reference_with<reference&&, value_type&>;
> > requires common_reference_with<reference&&, rvalue_reference&>;
> > requires common_reference_with<rvalue_reference&&, const
> value_type&>;
> > };
> >
> > Do you think it's worth supporting this using-alias syntax in the
> requires-clause?
>
> I think the best justification for this change is that it reduces
> repetition and thus makes it less likely to cause errors due to
> mistyping something. Most of those errors will be compile-time errors,
> but it's not unreasonable.
>
> That being said, you used standardese wrong. This is a
> requires-expression, not a requires-clause.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-08-16 16:12:47