C++ Logo


Advanced search

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

From: Kang Hewill <hewillk_at_[hidden]>
Date: Wed, 16 Aug 2023 23:39:00 +0800
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*
<https://eel.is/c++draft/iterator.concept.readable> 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>&> &&
iter_rvalue_reference_t<In>&&> &&
    common_reference_with<iter_rvalue_reference_t<In>&&, const

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


Received on 2023-08-16 15:39:12