RFC: replacing base::Contains()

15 views
Skip to first unread message

Victor Vianna

unread,
Dec 23, 2025, 2:41:30 PM (2 days ago) Dec 23
to c...@chromium.org
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 wrote Gemini 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:
  1. 66% can be replaced by a contains() method call
  2. 32% can be replaced by std::ranges::contains()
  3. 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
Reply all
Reply to author
Forward
0 new messages