<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi Chris,</p>
<p>To my knowledge, there isn't.</p>
<p>I don't recall where I got the idea, but I gave it a try last
summer trying to implement a clang-tidy check doing what you
proposed. I didn't have enough time to complete it, though, and I
only managed to detect one or two very simple patterns.</p>
<p>After thinking about this idea for some time I found that
clang-tidy might be a perfect place for that, not sure whether a
separate tool would be beneficial. The task of detecting a
specific pattern is very similar to what clang-tidy checks do in a
wide range of tasks. Also, there'd be a separate heuristic set for
each standard algorithm, which makes the partitioning into
different checks (for each popular standard library algorithm)
natural.</p>
<p>In my opinion, such checks would be useful, I'd be interested in
seeing a proof-of-concept of some sort.<br>
</p>
<p>One more idea I have in mind: it might be interesting to try
using CloneChecker (a check of Clang Static Analyzer) to detect
similar patterns in a generic way, but I'm not sure how beneficial
that would be in practice. Still, might worth a try.</p>
<p>+CC Alex, he might have some thoughts about this.<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</p>
<p>Kind regards,<br>
Kirill<br>
</p>
<br>
<div class="moz-cite-prefix">On 01/04/17 02:42, Christopher Di Bella
via cfe-dev wrote:<br>
</div>
<blockquote
cite="mid:CACL3gUVEhLoxZnMjjFdfirVx4mmtjzX4GOiOF4a5wFe+=SBp4Q@mail.gmail.com"
type="cite">
<div dir="ltr">Hey everyone,
<div><br>
</div>
<div>Just wondering if there's a clang tool that can analyse an
algorithm to suggest where standard algorithms can be replace
handwritten algos?</div>
<div>E.g.</div>
<div><br>
</div>
<div><font face="monospace">int i = 0;</font></div>
<div><font face="monospace">for (; i < v.size(); ++i)</font></div>
<div><font face="monospace"> if (v[i] == expected)</font></div>
<div><font face="monospace"> break;</font></div>
<div><font face="monospace">if (i != v.size())<br>
</font></div>
<div><font face="monospace"> some_function(v[i]);</font></div>
<div><font face="monospace"><br>
</font></div>
<div>Can be rewritten to</div>
<div><font face="monospace"><br>
</font></div>
<div><font face="monospace">auto i = find(v.begin(), v.end(),
expected);</font></div>
<div><font face="monospace">if (i != v.end())</font></div>
<div><font face="monospace"> some_function(*i);</font></div>
<div><br>
</div>
<div>or in C++17:</div>
<div><br>
</div>
<div><font face="monospace">if (auto i = find(v.begin(),
v.end(), expected); i != v.end())</font></div>
<div><font face="monospace"> some_function(*i);</font></div>
<div><br>
</div>
<div>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).</div>
<div><br>
</div>
<div>Cheers,</div>
<div><br>
</div>
<div>Chris</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>