chromium/v8/src/base/container-utils.h

// Copyright 2022 the V8 project 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 V8_BASE_CONTAINER_UTILS_H_
#define V8_BASE_CONTAINER_UTILS_H_

#include <algorithm>
#include <iterator>
#include <optional>
#include <vector>

namespace v8::base {

// Returns true iff the {element} is found in the {container}.
template <typename C, typename T>
bool contains(const C& container, const T& element) {}

// Returns the first index of {element} in {container}. Returns std::nullopt if
// {container} does not contain {element}.
template <typename C, typename T>
std::optional<size_t> index_of(const C& container, const T& element) {}

// Returns the index of the first element in {container} that satisfies
// {predicate}. Returns std::nullopt if no element satisfies {predicate}.
template <typename C, typename P>
std::optional<size_t> index_of_if(const C& container, const P& predicate) {}

// Removes {count} elements from {container} starting at {index}. If {count} is
// larger than the number of elements after {index}, all elements after {index}
// are removed. Returns the number of removed elements.
template <typename C>
inline size_t erase_at(C& container, size_t index, size_t count = 1) {}

// Removes all elements from {container} that satisfy {predicate}. Returns the
// number of removed elements.
// TODO(C++20): Replace with std::erase_if.
template <typename C, typename P>
inline size_t erase_if(C& container, const P& predicate) {}

// Helper for std::count_if.
template <typename C, typename P>
inline size_t count_if(const C& container, const P& predicate) {}

// Helper for std::all_of.
template <typename C, typename P>
inline bool all_of(const C& container, const P& predicate) {}
template <typename C>
inline bool all_of(const C& container) {}

// Helper for std::any_of.
template <typename C, typename P>
inline bool any_of(const C& container, const P& predicate) {}
template <typename C>
inline bool any_of(const C& container) {}

// Helper for std::none_of.
template <typename C, typename P>
inline bool none_of(const C& container, const P& predicate) {}

// Helper for std::sort.
template <typename C>
inline void sort(C& container) {}
template <typename C, typename Comp>
inline void sort(C& container, Comp comp) {}

// Returns true iff all elements of {container} compare equal using operator==.
template <typename C>
inline bool all_equal(const C& container) {}

// Returns true iff all elements of {container} compare equal to {value} using
// operator==.
template <typename C, typename T>
inline bool all_equal(const C& container, const T& value) {}

// Appends to vector {v} all the elements in the range {std::begin(container)}
// and {std::end(container)}.
template <typename V, typename C>
inline void vector_append(V& v, const C& container) {}

}  // namespace v8::base

#endif  // V8_BASE_CONTAINER_UTILS_H_