--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANFyMwyFRjZ9_qzh1%2BUs2ZCYDqfGzuT2%3DXPKJ%3DW55HWQH3bs6g%40mail.gmail.com.
a) That we allow use of std::ranges::contains() when C++23 is allowed (which is pending a styleguide CL and an email at this point)
2% (122 uses) can be replaced by find() calls. These could also be contains() if we introduced that method in the corresponding containers.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/1f55a5f7-d50a-4a04-af24-bb62e915ed93n%40chromium.org.
--
I forked an existing tool, wrote tests that failed initially [1][2], then asked Gemini to make the tool pass the tests. Later, I ran the tool, found cases I'd missed, wrote new tests and iterated with gemini.IIRC, at some point I told gemini to just read everything in tools/clang/ to get some inspiration.The main obstacle I ran into is that a lot of the existing tools didn't build successfully or didn't pass their tests. I have fixes for most of them (such as crrev.com/c/7268813), but didn't send all of them for review yet.> I think we could be making a lot better use of clang refactoring, if the barrier to get it set up were lower, so I'm interested to know how easy / repeatable it is to get Gemini to do it.Big +1. I had tried to write refactoring tools in the past and failed, so this is definitely an AI success story for me
--On Monday, January 5, 2026 at 6:50:41 PM UTC-3 Joe Mason wrote:As an aside - can you share your process for getting Gemini to write that tool?I think we could be making a lot better use of clang refactoring, if the barrier to get it set up were lower, so I'm interested to know how easy / repeatable it is to get Gemini to do it.On Tue, Dec 23, 2025 at 2:41 PM 'Victor Vianna' via cxx <c...@chromium.org> wrote:Hi cxx,C++23 brings std::ranges::contains() and std::basic_string::contains(). Together with previous C++20 additions like std::map::contains() and friends, that covers the vast majority of uses of base::Contains(). So we could now potentially remove the //base function.I wroteGemini wrote a clang refactoring tool that can do the job and allowed me to gather some statistics here. I ran the tool on 90% of the base::Contains() usages and observed that:
- 66% can be replaced by a contains() method call
- 32% can be replaced by std::ranges::contains()
- 2% (122 uses) can be replaced by find() calls. These could also be contains() if we introduced that method in the corresponding containers.
So I'd like to propose 2 things:a) That we allow use of std::ranges::contains() when C++23 is allowed (which is pending a styleguide CL and an email at this point)b) That we migrate base::Contains() using the tool above.-- Victor--You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANFyMwyFRjZ9_qzh1%2BUs2ZCYDqfGzuT2%3DXPKJ%3DW55HWQH3bs6g%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/5f907f46-b6da-4b3f-b398-c8955e9ee7bcn%40chromium.org.
I'm in favour of changing to the standard methods and functions, but 122 uses are enough to justify the existence of base::Contains() by themselves. I wouldn't want to change them to use find() as it is a loss in readability*. Ideally we would add contains() methods to all the containers involved, but I don't know how realistic that is.Footnote:There are some cases where find() is better. I've seen code likeif (base::Contains(map, key)) {auto it = map.find(key);...}which is better written asif (auto it = map.find(key); it != map.end()) {...}I don't know if it's possible for a clang refactoring tool to fix things like that.
I forked an existing tool, wrote tests that failed initially [1][2], then asked Gemini to make the tool pass the tests. Later, I ran the tool, found cases I'd missed, wrote new tests and iterated with gemini.IIRC, at some point I told gemini to just read everything in tools/clang/ to get some inspiration.The main obstacle I ran into is that a lot of the existing tools didn't build successfully or didn't pass their tests. I have fixes for most of them (such as crrev.com/c/7268813), but didn't send all of them for review yet.
> I think we could be making a lot better use of clang refactoring, if the barrier to get it set up were lower, so I'm interested to know how easy / repeatable it is to get Gemini to do it.Big +1. I had tried to write refactoring tools in the past and failed, so this is definitely an AI success story for me--On Monday, January 5, 2026 at 6:50:41 PM UTC-3 Joe Mason wrote:As an aside - can you share your process for getting Gemini to write that tool?I think we could be making a lot better use of clang refactoring, if the barrier to get it set up were lower, so I'm interested to know how easy / repeatable it is to get Gemini to do it.On Tue, Dec 23, 2025 at 2:41 PM 'Victor Vianna' via cxx <c...@chromium.org> wrote:Hi cxx,C++23 brings std::ranges::contains() and std::basic_string::contains(). Together with previous C++20 additions like std::map::contains() and friends, that covers the vast majority of uses of base::Contains(). So we could now potentially remove the //base function.I wroteGemini wrote a clang refactoring tool that can do the job and allowed me to gather some statistics here. I ran the tool on 90% of the base::Contains() usages and observed that:
- 66% can be replaced by a contains() method call
- 32% can be replaced by std::ranges::contains()
- 2% (122 uses) can be replaced by find() calls. These could also be contains() if we introduced that method in the corresponding containers.
So I'd like to propose 2 things:a) That we allow use of std::ranges::contains() when C++23 is allowed (which is pending a styleguide CL and an email at this point)b) That we migrate base::Contains() using the tool above.-- Victor--You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANFyMwyFRjZ9_qzh1%2BUs2ZCYDqfGzuT2%3DXPKJ%3DW55HWQH3bs6g%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/5f907f46-b6da-4b3f-b398-c8955e9ee7bcn%40chromium.org.