// Copyright 2011 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Derived from google3/util/gtl/stl_util.h #ifndef BASE_STL_UTIL_H_ #define BASE_STL_UTIL_H_ #include <algorithm> #include <forward_list> #include <iterator> #include <type_traits> #include "base/check.h" #include "base/ranges/algorithm.h" namespace base { namespace internal { IsRandomAccessIter; } // namespace internal // Returns a const reference to the underlying container of a container adapter. // Works for std::priority_queue, std::queue, and std::stack. template <class A> const typename A::container_type& GetUnderlyingContainer(const A& adapter) { … } // Clears internal memory of an STL object. // STL clear()/reserve(0) does not always free internal memory allocated // This function uses swap/destructor to ensure the internal memory is freed. template<class T> void STLClearObject(T* obj) { … } // Returns a new ResultType containing the difference of two sorted containers. template <typename ResultType, typename Arg1, typename Arg2> ResultType STLSetDifference(const Arg1& a1, const Arg2& a2) { … } // Returns a new ResultType containing the union of two sorted containers. template <typename ResultType, typename Arg1, typename Arg2> ResultType STLSetUnion(const Arg1& a1, const Arg2& a2) { … } // Returns a new ResultType containing the intersection of two sorted // containers. template <typename ResultType, typename Arg1, typename Arg2> ResultType STLSetIntersection(const Arg1& a1, const Arg2& a2) { … } // A helper class to be used as the predicate with |EraseIf| to implement // in-place set intersection. Helps implement the algorithm of going through // each container an element at a time, erasing elements from the first // container if they aren't in the second container. Requires each container be // sorted. Note that the logic below appears inverted since it is returning // whether an element should be erased. template <class Collection> class IsNotIn { … }; } // namespace base #endif // BASE_STL_UTIL_H_