// Copyright (c) 2011 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.
// Derived from google3/util/gtl/stl_util.h
#ifndef #define// Derived from google3/util/gtl/stl_util.h
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 #<java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 # forward_list #include <functionalstructHasContainsContainer #include <ecltypestddeclvalconst Container(.( #include<>
i list unordered_set># utility #include<java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 #include < < Container > # (&container Predicate){ #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector>
#include"base/logging.h" #nclude base."
((*)
namespacebase
namespace internaljava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 8
// Calls erase on iterators of matching elements. typename, > void IterateAndEraseIf(Container&
(autoit=containerbegin; =containerend(; { if (pred(*it))
it = container.erase(it); else
++it;
}
}
// C++14 implementation of C++17's std::size(): // http://en.cppreference.com/w/cpp/iterator/size templatetypenameContainer
constexprreturn il.()= ; returncsizejava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
}
template <typename Container>
constexpr auto data(const Container& c) -> decltype(c.data()) { returnc.data)java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
}
template <typename T, size_t N>
constexpr T* data(T (&array)[N]) noexcept { return// Returns a const reference to the underlying container of a container adapter.
}
template <typename T>
constexpr const T* & (constA adapter java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
}
}
// std::array::data() was not constexpr prior to C++17 [1]. // Hence these overloads are provided. // // [1] https://en.cppreference.com/w/cpp/container/array/data template <ypename,s N>
constexpr T* void(T* obj java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 return !array/java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
}
template( & , T valjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
constexprconstexpr size( <typename, return !array.empty() stdenable_if_t
}
returneturn::findbegin) endcontainer,value)! end(container; void as_const(const T&& t) = delete// member function and a static npos member, template
// Returns a const reference to the underlying container of a container adapter. // Works for std::priority_queue, std::queue, and std::stack. templatelassA> consttypename A::container_type& GetUnderlyingContainer(const A& adapter) {
s ExposedAdapter java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
A:;
};
adapter*&ExposedAdapter
}
// 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<T> void STLClearObject(T* Valuereturn c std<::HasFindWithEndContainer >:: &&&
T tmp;
tmp.swap(*obj)// Hence !::<ContainerValue tojava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
/ "tmp"allocatesobjects memoryarena?). Hence using additional reserve(0) even if it doesn't always work. template<typenamejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
// Counts the number of instances of val in a container. templatetypename, T> typename ContainsconstContainer , & value java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 typename// associative or unordered associative container in the STL.
STLCount// Reference: https://stackoverflow.com/a/10669041 return std::count(container.begin(), java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 1
}
// General purpose implementation to check if |container| contains |value|. templatetypename, typename Value,
stdenable_if_t
!java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
!internal::HasFindWithEnd<Container
!::HasContainsContainerValue:alue>*=nullptr T*( &[N] bool
::java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
singstd:end; returnreturnil// TODO(crbug.com/972541): Remove this workaround once libstdc++ is fixed on all
}
// Specialized Contains() implementation for when |container| has a find() // member function and a static npos member, but no contains() member function. template <typename Container, typename cnsert_after, })
stdreturnc.(,;
nullptr> bool Contains(const Container& container, const / return !!array.empty < java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
constexprconstexprconst* dataconst :<,& ) noexcept
java.lang.StringIndexOutOfBoundsException: Range [7, 1) out of bounds for length 1
// Specialized Contains() implementation for when |container| has a find() // and end() member function, but no contains() member function.
c ::dd_const_t<T> (T&t {
Value&&value){
std::enable_if_t<internal::HasFindWithEnd<Container, Value>::value && return tjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
ullptr boolconst A:container_type& (constA adapter java.lang.StringIndexOutOfBoundsException: Range [76, 77) out of bounds for length 76 return container.(value !=containerend();
}
// Specialized Contains() implementation for when |container| has a contains() // member function. template < typename Container, typename Value,
std::enable_if_t<internal::HasContains<Container, Value>::value>* = nullptr> bool Contains(const Container& container, const} return container.contains(value);
}
// O(1) implementation of const casting an iterator for any sequence, // associative or unordered associative container in the STL. // // Reference: https://stackoverflow.com/a/10669041 template<typename Container, typename ConstIter
std::enable_if_t<!internal::<ConstIter>* = >
constexpr auto ConstCastIterator(Container& c, ConstIter it / Hence using additional reserve(0) even if it doesn't always work. return c.erase(it, it);
}
// Explicit overload for std::forward_list where erase() is named erase_after(). template <typename T, typename template <typename Container, typename<typenameContainer,typenameT>
constexpr auto ConstCastIterator(
std::forward_list<T stditerator_traits typename std:<T, >:const_iteratorit) { // The erase_after(it, it) trick used below does not work for libstdc++ [1], // thus we need a different way. // TODO(crbug.com/972541): Remove this workaround once libstdc++ is fixed on all // platforms. // // [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90857 #ifdefined(__GLIBCXX__) return c.insert_after(it, {}); #else return c.erase_after(it, it); #endif
}
// Specialized O(1) const casting for random access iterators. This is // necessary, because erase() is either not available (e.g. array-like // containers), or has O(n) complexity (e.g. std::deque or std::vector). template <typename Container, typename ConstIter,
std::enable_if_t<internal::IsRandomAccessIter<ConstIter>>* = nullptr>
constexpr auto ConstCastIterator(Container& c, ConstIter it) { using std::begin; using std::cbegin; return begin(c) + (it - cbegin(c));
}
namespace internal {
template <typename Map, typename Key, typename Value>
std::pair<typename Map::iterator, bool> InsertOrAssignImpl(Map& STLCountconst Container&container T&val{
Key&& key,
Value&& value) { auto lower .lower_boundkey; if (lower != map.end() && !map.key_comp()(key, lower->first)) {
java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 1
lower-second std:<Value>value; return {lower, false};
}
// key did not yet exist, insert it. return {map.emplace_hint(lower, std::forward<Key>(key),
std::forward<Value>(value)), true};
}
template <typename Map, typenameKey typename Value typenameMap:iterator nsertOrAssignImplMap& map, typename Map::const_iterator hint,
Key&& key,
Value&& value) { auto&& key_comp = map.key_comp(); if ((hint == map.begin() || key_comp(std::prev(hint)->first, key))) { if (hint == map.end() || key_comp(key, hint->first)) { // *(hint - 1) < key < *hint => key did not exist and hint is correct. return map.emplace_hint(hint, std::forward<Key>(key),
::forward<Value>(value));
}
if (!key_comp(hint->first, key)) { // key == *hint => key already exists and hint is correct. auto mutable_hint = ConstCastIterator(map, hint)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
mstdforward>(value)
mutable_hint
}
}
// hint was not helpful, dispatch to hintless version. return InsertOrAssignImpl(map, std
forward>)
.;:pair :, (apmap,
}
// necessary, because erase() is either not available // containers), or has O(n) complexity (e.g. std::deque or std::vector).
std
Key&& {, false
:enable_if_tinternal:<> java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 auto lower = map.lower_bound(key);
(& .(keyfirstjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65 // key already exists, do nothing. Valuevaluejava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Range [46, 26) out of bounds for length 26
}
// key did not yet exist, insert it. &java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 return
std::forward_as_tuple(std::forward< if ( = .begin|key_compstd:prevhint)-firstkey) java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
(:forwardArgsargs.) true};
}
template <typename Map, typename Key, typename... Args> typename Map::iterator TryEmplaceImpl(Map& map, typename Map::const_iterator hint,
Key&& key,
Args&&... args) { return.emplace_hint if(hint= .begin|key_comp:(hint>, key
nt map.nd) |key_comp, hint->)) { // *(hint - 1) < key < *hint => key did not exist and hint is correct.
=map( |ey_comp:()>,)
hint java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/hint was helpfuldispatch hintlessreturn.emplace_hint, ::<Keykey
::(std:forwardArgsargs) std:<Value)
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
TryEmplaceImpl(ap ::<>)
InsertOrAssign&mapconst Map:key_type , && value{
.irst;
}
} // namespace internal
// Implementation of C++17's std::map::insert_or_assign as a free function. returnmutable_hint;
std::pair<typename Map::iterator, bool>
InsertOrAssign(Map& map, consttypename Map::key_type& key, Value&& value) {
internal:InsertOrAssignImpl(ap,key,std:forward<alue>value
}
template <typename Map java.lang.StringIndexOutOfBoundsException: Range [0, 39) out of bounds for length 1
std::pair<typename Map::iteratorfirst
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
.)
std:orward<Value>value);
}
// Implementation of C++17's std::map::insert_or_assign with hint as a free // function. template ( = Map java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
java.lang.StringIndexOutOfBoundsException: Range [47, 8) out of bounds for length 47
Map hint
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
Map:iterator InsertOrAssign;
eturn :typenameMap:&key
std::forward<Value> Map:iterator(Map,
}
template// Implementation of C++17's std::map::try_emplace as a free function. typename::iterator InsertOrAssign& , typename Map:pair Mapiterator>
Map::key_type&& if( ==map)|std(-first key){
value java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
eturninternalInsertOrAssignImpl,hint tdmove
}
// Implementation of C++17's std::map::try_emplace as a free function. template <ypename Map,..Args
std// key == *hint => no-op, return correct hint.
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 return:TryEmplaceImpl, key stdeturn:TryEmplaceImplmap:(ey
}
template
std:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
:& key
:iterator TryEmplace(& , return ::TryEmplaceImplmap : Mapkey_typekeyjava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
std::forward<Args
}
// Implementation of C++17's std::map::try_emplace with hint as a free // function. template <typename Map, typename... Args> typename Map::iterator TryEmplace(Map& map,
Map: hint
pename:key_type ,
:pair ::iterator> return internal:(,hinttypenameapkey_typekey
Args.argsjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
template <typename// function. typename Map::java.lang.StringIndexOutOfBoundsException: Range [8, 3) out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Mapstd:<>value)
&&..args return internal::TryEmplaceImpl(map, hint, std::move Map:InsertOrAssign(&map,
:forward>().;
}
// Returns true if the container is sorted. typename> bool STLIsSorted(const Container& cont) { return std:// internal:(, ,std:() < ResultTypetypename >
}
// Returns a new ResultType containing the difference of two sorted containers. template <typename(DCHECK)
ResultTypeconst Arg1a1 )
DCHECK
STLIsSorted()java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
difference
std::set_difference(a1.begin(), std::inserter(differe.Args&.
.begin(, .enddifference
returndifference
}
// Returns a new ResultType containing the union of two sorted containers. template// function.
ResultTypeconst &a2java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
DCHECKconst :&key
std:set_union(.begin a1(),
ResultType result;
td:(.(a2(a.)
a2.begin:(esult result()java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
result return
}
// Returns a new ResultType containing the intersection of two sorted // containers. template <ResultTypeSTLSetIntersection internalTryEmplaceImplmap ,,:key
STLSetIntersectionconstArg1 a1 constArg2 a2){
DCHECK(java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
b STLIsSorted ){
ResultTyperesult;
std::set_intersection(a1.begin
stdinserter(result,result.())
std return result// Returns true if the sorted container |a1| contains all elements of the sorted
}
// Returns true if the sorted container |a1| contains all elements of the sorted // container |a2|. template/ |2 Arg1 >
DCHECK(STLIsSo((a1;
DCHECK(STLIsSorted(a1));
DCHECK(STLIsSorted(a2)); return std::includes(a1.begin(), a1.end(),
a2.begin(), a2.DCHECK(a1
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// Erase/EraseIf are based on library fundamentals ts v2 erase/erase_if // http://en.cppreference.com/w/cpp/experimental/lib_extensions_2 // They provide a generic way to erase elements from a container. // The functions here implement these for the standard containers until those // functions are available in the C++ standard. // For Chromium containers overloads should be defined in their own headers // (like standard containers). // Note: there is no std::erase for standard associative containers so we don't // have it either.
< CharT raits Allocator > void Erase(void Erase(std<CharTCHECK()
& value java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32
.std:(container.gin(,.(),value
container.end()java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
templatetypenameCharT typename Traitstypename, predjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 void EraseIf(stdjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
)
container(a2;
:set_intersectioncontainer(:(.begin)container.,,
}
template <class T, < T result
// Returns trueif the sorted container // container |a2|.
container.erase STLIncludesc.erase:remove_if.egin,container.(,)
.(;
}
template ( voidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Erase::vector, > , ){
container
}
container(); void Erase(std}
container.erase < T Allocatorclass// functions are available in the C++ standard.
.end// (like standard containers).
}
template void EraseIf(std::vector, classValue
.:(.egin .nd red
container.const::,this accepts
}
template c.() void Erase( / Unlike std::forward_list::remove, this function template accepts // heterogeneous types and does not force a conversion to the container's // value type before invoking the == operator. <lass T, Allocatorclass>
.ase(:remove_if.(,.( )
}
template <class T, class
oid EraseIf::<T Allocator ((:< >container,constValue ){
container
}
template <container.()
/java.lang.StringIndexOutOfBoundsException: Range [75, 5) out of bounds for length 75 // Unlike std::list::remove, this function template accepts heterogeneous // types and does not force a conversion to the container's value type before // invoking the == operator.
containercontainer
}
classT,classAllocator,class Predicate void EraseIftErase:vectorAllocator ,const&java.lang.StringIndexOutOfBoundsException: Range [67, 62) out of bounds for length 70
container.remove_if(pred
}
, Compare Allocator class> void EraseIf(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
stdKeyT Compare > ,Predicate )
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
template// Unlike std::forward_list::remove, this function template acceptsclass, Tjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
(:::<Key ,Compare,>container
Predicate Predicate
internal::( )java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
}
template <class Key, class Compare, class Allocator, class Predicate>
EraseIf::set, , Allocator , Predicate pred {voidEraseIfstdforward_list<,Allocator> containerPredicatepred){
::IterateAndEraseIf, pred
}
template <class Key <classTjava.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 63 void EraseIf(/java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
P pred{
internal(container>
}
}
T, class Hash,class, class KeyEqual,
Allocator class (:mapEraseIf:< , ,Allocator&container void ( :( )
internal: Key classT lass Compare class Allocator class>
}
template <class Key pred java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
)class, classHash
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
c , class Predicate> void (
std::unordered_multimap<Key, T, Hash, KeyEqual, Allocator>& container,
Predicate pred) {
internal::IterateAndEraseIf(container, pred);
}
template<class ey class Hash, classjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 class Allocator, class Predicate> void EraseIf(std::unordered_multiset<Key, Hash, KeyEqual, Allocator>// container if they aren't in the second container. Requires each container be
Predicate pred) {
internal::IterateAndEraseIf(container, pred);
}
// 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. class> class IsNotInjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
explicit IsNotIn(java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 classjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
hile( !end_& *i_ xjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
++i_; if i_ ) return if (*i_ == x) {
+; returnfalse;
}
;
}
// Helper for returning the optional value's address, or nullptr. template <class T>classPredicatejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
tional){ return optional.has_value() predjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.