Our organization is looking to standardize the way we use const T& and T const& and while we initially looked at clang-format to solve the job, it doesn't reorder tokens so there is no way to swap const and T.

Does anyone have an idea as to how I can reorder these systematically?

  • Hi and welcome. Why not use a simple search and replace with a regex? – Paul92 Feb 3 '17 at 22:43
  • 3
    So you are going introduce a risk of breaking something by introducing a change which does not really improve the readabilty of the code, just make it a little bit more consistent? Sure it will be worth the hassle? – Doc Brown Feb 3 '17 at 22:49
  • 2
    I'm not sure if it is worth the hassle. If the answer is sed magic followed by clang format, I'm too afraid of making a mistake by the changing something in a string context or messing up with a const function. If there is a tool that does this already then it might be worth the hassle. – Jon Feb 4 '17 at 3:10
  • I'm sure that the more intrusive Clang tools (modernize) can perform this transformation. But I have no experience in using them. – 5gon12eder Feb 4 '17 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.