testuser2 / hadesmem

Automatically exported from code.google.com/p/hadesmem
0 stars 0 forks source link

[FindPattern.cpp] Constness, passing as reference #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not sure if I'm right here (terrible at proper C++), anyhow:

FindPattern.cpp, Line 163-168 
(http://code.google.com/p/hadesmem/source/browse/trunk/Memory/Memory/FindPattern
.cpp?r=789#163 )

      auto Iter = std::search(Buffer.begin(), Buffer.end(), Data.begin(), 
        Data.end(), 
        [&] (BYTE HCur, std::pair<BYTE, bool> NCur)
      {
        return (!NCur.second) || (HCur == NCur.first);
      });

Would calls to cbegin/cend (both for the Buffer and the Data vectors) be more 
appropriate?

For the lambda function, is the & necessary? No variables are being used inside 
the lambda function other than the passed arguments. And could NCur be passed 
as a reference-to-const instead?

[](BYTE HCur, std::pair<BYTE, bool> const& NCur)

If I'm totally wrong here then at least I learned something from it. :-)

Best,

sku

Original issue reported on code.google.com by ochm...@gmail.com on 30 Dec 2010 at 1:31

GoogleCodeExporter commented 9 years ago
You're correct on all three counts. Fixed.

The only one that could be disputed is the third point (about passing the pair 
by reference-to-const). Nevertheless, I've 'fixed' it.

Thanks.

Original comment by therapto...@gmail.com on 30 Dec 2010 at 2:34