This is a starting point to improve the handling of concepts in clang-format. There is currently no real formatting of concepts and this can lead to some odd formatting, e.g.
requires(R range) {
typename Iterator_type<R>;
{ begin(range) }
->Iterator_type<R>;
{ end(range) }
->Iterator_type<R>;
requires Input_iterator<Iterator_type<R>>();
};
template <typename T> concept Large = sizeof(T) > 10;
template <typename T, typename U> concept FooableWith = requires(T t, U u) {
typename T::foo_type;
{ t.foo(u) }
->typename T::foo_type;
t++;
};The revision starts by resolving the additional newline added before the implicit conversion constraint and ensures that the concept keyword is always on the line below template<>
template <typename T>
concept bool EqualityComparable = requires(T a, T b) {
{ a == b } -> bool;
};Additional Options include the following to allow a 1 level indentation of the requires clauses (as seems to be popular in a couple of sources, online reference and conference slides about concepts)
- IndentRequires (indent the "requires keyword after template")
e.g.
template <class I, class S>
requires Sentinel<S, I>()
constexpr void advance(I &i, S bound) noexcept(noexcept(++i != bound)) {
while (i != bound) {
++i;
}
}
It would be nice to have an example here in the doc.