Skip to content

[feature request] requires clause in functions (concepts TS) #31514

Closed
@gnzlbg

Description

Bugzilla Link 32166
Version trunk
OS All
CC @CaseyCarter,@HazardyKnusperkeks,@mydeveloperday

Extended Description

This code

template <bool IsConst>
struct A {
  void prev() 
  requires BidirectionalIterator<iterator_t<IsConst>>() &&
           BidirectionalIterator<iterator_t<IsConst>>() &&
           BidirectionalIterator<iterator_t<IsConst>>() 
  { --it_; }
};

gets formatted into:

template <bool IsConst>
struct A {
  void prev() requires BidirectionalIterator<iterator_t<IsConst>>() &&
      BidirectionalIterator<iterator_t<IsConst>>() &&
      BidirectionalIterator<iterator_t<IsConst>>() {
    --it_;
  }
};

I don't see a reason why the options specified in #​32165 shouldn't apply here as well.

Also: https://github.com/CaseyCarter/cmcstl2/blob/43b63f6846d80bcd1867f512519bc18841bd961e/include/stl2/detail/iterator/operations.hpp#L25

this code:

template <class I>
requires
        Iterator<I>()
        // Pre: 0 <= n && [i,i+n)
constexpr void impl(I& i, difference_type_t<I> n)
noexcept(noexcept(++std::declval<I&>()))
{
    STL2_EXPECT(0 <= n);
    while (n != 0) {
        --n;
        ++i;
    }
}

gets formatted into

template <class I>
requires Iterator<I>()
    // Pre: 0 <= n && [i,i+n)
    constexpr void impl(I& i, difference_type_t<I> n) noexcept(
        noexcept(++std::declval<I&>())) {
  STL2_EXPECT(0 <= n);
  while (n != 0) {
    --n;
    ++i;
  }
}

(Note how the constexpr keywords is not aligned with the template keyword).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions