diff options
Diffstat (limited to 'cc/scoped_ptr_algorithm.h')
-rw-r--r-- | cc/scoped_ptr_algorithm.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cc/scoped_ptr_algorithm.h b/cc/scoped_ptr_algorithm.h new file mode 100644 index 0000000..2972b00 --- /dev/null +++ b/cc/scoped_ptr_algorithm.h @@ -0,0 +1,30 @@ +// Copyright 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_SCOPED_PTR_ALGORITHM_H_ +#define CC_SCOPED_PTR_ALGORITHM_H_ + +namespace cc { + +// ScopedContainers need to implement a swap() method since they do not allow +// assignment to their iterators. +template <class ForwardIterator, class Predicate, class ScopedContainer> +ForwardIterator remove_if( + ScopedContainer& container, + ForwardIterator first, + ForwardIterator last, + Predicate predicate) { + ForwardIterator result = first; + for (; first != last; ++first) { + if (!predicate(*first)) { + container.swap(first, result); + ++result; + } + } + return result; +} + +} // namespace cc + +#endif // CC_SCOPED_PTR_ALGORITHM_H_ |