Getting clang-format to format requires-expression on one line
Asked Answered
L

1

6

Here is my code:

if constexpr (requires { { N::uuid() } -> std::convertible_to<score::uuid_t>; })

clang-format (14, 15) insists in formatting it in 5 lines:

if constexpr (requires {
                {
                  N::uuid()
                  } -> std::convertible_to<score::uuid_t>;
              })

which is insane, how can I ensure that it stays on one line without having to annotate every single line ?

Lianaliane answered 29/6, 2022 at 9:6 Comment(1)
This has been irking me as well, but unfortunately I don't think it's possible as of version 15. A minimally invasive workaround is to write all constraints as concepts, and group those in a section or file you exclude from formatting.Rotl
M
1

Starting with clang v18 (which is still in release candidate as of the time of writing - February 21, 2024), there will be the option AllowShortCompoundRequirementOnASingleLine.

Myocardiograph answered 21/2 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.