[cfe-dev] C++ algorithm analysis tool

Christopher Di Bella via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 31 16:42:43 PDT 2017


Hey everyone,

Just wondering if there's a clang tool that can analyse an algorithm to
suggest where standard algorithms can be replace handwritten algos?
E.g.

int i = 0;
for (; i < v.size(); ++i)
   if (v[i] == expected)
      break;
if (i != v.size())
   some_function(v[i]);

Can be rewritten to

auto i = find(v.begin(), v.end(), expected);
if (i != v.end())
   some_function(*i);

or in C++17:

if (auto i = find(v.begin(), v.end(), expected); i != v.end())
   some_function(*i);

If not, how difficult a task is it to write such a tool? Is there anything
that one should take into special consideration while writing this tool? Do
you think it would have a lot of use-cases? (I do, based on my company's
code base, and code I have seen while marking assignments).

Cheers,

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170331/d02af636/attachment.html>


More information about the cfe-dev mailing list