Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
gtl Namespace Reference

Namespaces

namespace  detail
 
namespace  internal
 
namespace  stl_util_internal
 

Classes

class  BaseDeleter
 
class  ElementDeleter
 
class  IntType
 
class  linked_hash_map
 
struct  LogLegacy
 
struct  LogLegacyUpTo100
 
struct  LogMultiline
 
struct  LogMultilineUpTo100
 
class  LogMultilineUpToN
 
struct  LogShort
 
struct  LogShortUpTo100
 
class  LogShortUpToN
 
class  ReverseView
 
class  small_map
 
class  STLElementDeleter
 
class  STLValueDeleter
 
class  TemplatedElementDeleter
 
class  TemplatedValueDeleter
 
class  ValueDeleter
 

Typedefs

typedef LogShortUpTo100 LogDefault
 The default policy for new code.
 
template<typename M >
using MapUtilValueT = typename M::value_type
 
template<typename M >
using MapUtilKeyT = typename MapUtilValueT<M>::first_type
 
template<typename M >
using MapUtilMappedT = typename MapUtilValueT<M>::second_type
 

Functions

template<typename IteratorT , typename PolicyT >
void LogRangeToStream (std::ostream &out, IteratorT begin, IteratorT end, const PolicyT &policy)
 
template<typename IteratorT , typename PolicyT >
detail::RangeLogger< IteratorT, PolicyT > LogRange (const IteratorT &begin, const IteratorT &end, const PolicyT &policy)
 
template<typename IteratorT >
detail::RangeLogger< IteratorT, LogDefaultLogRange (const IteratorT &begin, const IteratorT &end)
 
template<typename ContainerT , typename PolicyT >
auto LogContainer (const ContainerT &container, const PolicyT &policy) -> decltype(gtl::LogRange(container.begin(), container.end(), policy))
 
template<typename ContainerT >
auto LogContainer (const ContainerT &container) -> decltype(gtl::LogContainer(container, LogDefault()))
 
template<typename E >
detail::EnumLogger< E > LogEnum (E e)
 
template<typename IntTypeName , typename ValueType >
std::ostream & operator<< (std::ostream &os, IntType< IntTypeName, ValueType > arg)
 
 INT_TYPE_ARITHMETIC_OP (+)
 
 INT_TYPE_ARITHMETIC_OP (-)
 
INT_TYPE_ARITHMETIC_OP * INT_TYPE_ARITHMETIC_OP (/);INT_TYPE_ARITHMETIC_OP(<<
 
 INT_TYPE_ARITHMETIC_OP (> >)
 
 INT_TYPE_ARITHMETIC_OP (%)
 
 INT_TYPE_COMPARISON_OP (==)
 
 INT_TYPE_COMPARISON_OP (!=)
 
 INT_TYPE_COMPARISON_OP (<=)
 
 INT_TYPE_COMPARISON_OP (>=)
 
template<class Container >
ReverseView< Container > reversed_view (const Container &c)
 
template<typename Collection , typename KeyType = MapUtilKeyT<Collection>>
const MapUtilMappedT< Collection > & FindWithDefault (const Collection &collection, const KeyType &key, const MapUtilMappedT< Collection > &value)
 
template<class Collection , typename KeyType = MapUtilKeyT<Collection>>
const MapUtilMappedT< Collection > & FindWithDefault (const Collection &collection, const KeyType &key)
 
template<class Collection >
const Collection::value_type::second_type * FindOrNull (const Collection &collection, const typename Collection::value_type::first_type &key)
 
template<class Collection >
Collection::value_type::second_type * FindOrNull (Collection &collection, const typename Collection::value_type::first_type &key)
 
template<class Collection >
const Collection::value_type::second_type FindPtrOrNull (const Collection &collection, const typename Collection::value_type::first_type &key)
 
template<class Collection , class Key , class Value >
bool InsertOrUpdate (Collection *const collection, const Key &key, const Value &value)
 
template<class Collection >
bool InsertIfNotPresent (Collection *const collection, const typename Collection::value_type &value)
 
template<class Collection , class Key , class Value >
bool InsertIfNotPresent (Collection *const collection, const Key &key, const Value &value)
 
template<class Collection >
void InsertOrDieNoPrint (Collection *const collection, const typename Collection::value_type &value)
 
template<class Collection >
void InsertOrDie (Collection *const collection, const typename Collection::value_type &value)
 
template<class Collection >
void InsertOrDie (Collection *const collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &data)
 
template<typename Collection >
auto & InsertKeyOrDie (Collection *const collection, const typename Collection::value_type::first_type &key)
 
template<class Collection , class Key , class Value >
bool FindCopy (const Collection &collection, const Key &key, Value *const value)
 
template<class Collection , class Key >
bool ContainsKey (const Collection &collection, const Key &key)
 
template<class Collection >
const Collection::value_type::second_type & FindOrDie (const Collection &collection, const typename Collection::value_type::first_type &key)
 
template<class Collection >
const Collection::value_type::second_type & FindOrDieNoPrint (const Collection &collection, const typename Collection::value_type::first_type &key)
 Same as FindOrDie above, but doesn't log the key on failure.
 
template<class Collection >
Collection::value_type::second_type & FindOrDieNoPrint (Collection &collection, const typename Collection::value_type::first_type &key)
 Same as above, but returns a non-const reference.
 
template<class Collection >
Collection::value_type::second_type & LookupOrInsert (Collection *const collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
 
template<typename T , typename LessFunc >
void STLSortAndRemoveDuplicates (T *v, const LessFunc &less_func)
 
template<typename T >
void STLSortAndRemoveDuplicates (T *v)
 
template<typename T , typename LessFunc >
void STLStableSortAndRemoveDuplicates (T *v, const LessFunc &less_func)
 
template<typename T >
void STLStableSortAndRemoveDuplicates (T *v)
 
template<typename T , typename E >
void STLEraseAllFromSequence (T *v, const E &e)
 
template<typename T , typename A , typename E >
void STLEraseAllFromSequence (std::list< T, A > *c, const E &e)
 
template<typename T , typename A , typename E >
void STLEraseAllFromSequence (std::forward_list< T, A > *c, const E &e)
 
template<typename T , typename P >
void STLEraseAllFromSequenceIf (T *v, P pred)
 Remove each element e in v satisfying pred(e).
 
template<typename T , typename A , typename P >
void STLEraseAllFromSequenceIf (std::list< T, A > *c, P pred)
 
template<typename T , typename A , typename P >
void STLEraseAllFromSequenceIf (std::forward_list< T, A > *c, P pred)
 
template<typename T >
void STLClearObject (T *obj)
 
template<typename T , typename A >
void STLClearObject (std::deque< T, A > *obj)
 STLClearObject overload for deque, which is missing reserve().
 
template<typename T >
void STLClearIfBig (T *obj, size_t limit=1<< 20)
 
template<typename T , typename A >
void STLClearIfBig (std::deque< T, A > *obj, size_t limit=1<< 20)
 STLClearIfBig overload for deque, which is missing capacity().
 
template<typename T >
void STLClearHashIfBig (T *obj, size_t limit)
 
void STLStringReserveIfNeeded (std::string *s, size_t min_capacity)
 
template<typename T , typename Traits , typename Alloc >
void STLStringResizeUninitialized (std::basic_string< T, Traits, Alloc > *s, size_t new_size)
 
template<typename T , typename Traits , typename Alloc >
bool STLStringSupportsNontrashingResize (const std::basic_string< T, Traits, Alloc > &s)
 
void STLAssignToString (std::string *str, const char *ptr, size_t n)
 
void STLAppendToString (std::string *str, const char *ptr, size_t n)
 
char * string_as_array (std::string *str)
 
template<typename HashSet >
bool HashSetEquality (const HashSet &set_a, const HashSet &set_b)
 
template<typename HashMap , typename BinaryPredicate >
bool HashMapEquality (const HashMap &map_a, const HashMap &map_b, BinaryPredicate mapped_type_equal)
 
template<typename K , typename V , typename C , typename A >
bool HashMapEquality (const std::map< K, V, C, A > &map_a, const std::map< K, V, C, A > &map_b)
 
template<typename HashMap >
bool HashMapEquality (const HashMap &a, const HashMap &b)
 
template<typename ForwardIterator >
void STLDeleteContainerPointers (ForwardIterator begin, ForwardIterator end)
 
template<typename ForwardIterator >
void STLDeleteContainerPairPointers (ForwardIterator begin, ForwardIterator end)
 
template<typename ForwardIterator >
void STLDeleteContainerPairFirstPointers (ForwardIterator begin, ForwardIterator end)
 
template<typename ForwardIterator >
void STLDeleteContainerPairSecondPointers (ForwardIterator begin, ForwardIterator end)
 
template<typename T >
void STLDeleteElements (T *container)
 
template<typename T >
void STLDeleteValues (T *v)
 
template<typename T >
ABSL_MUST_USE_RESULT T * release_ptr (T **ptr)
 
template<typename In1 , typename In2 , typename Out , typename Compare >
void STLSetDifference (const In1 &a, const In2 &b, Out *out, Compare compare)
 
template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type STLSetDifference (const In1 &a, const In2 &b, Out *out)
 
template<typename Out , typename In1 , typename In2 , typename Compare >
Out STLSetDifferenceAs (const In1 &a, const In2 &b, Compare compare)
 Explicit comparator, explicit return type.
 
template<typename Out , typename In1 , typename In2 >
Out STLSetDifferenceAs (const In1 &a, const In2 &b)
 Implicit comparator, explicit return type.
 
template<typename In1 , typename In2 , typename Compare >
In1 STLSetDifference (const In1 &a, const In2 &b, Compare compare)
 Explicit comparator, implicit return type.
 
template<typename In1 , typename In2 >
In1 STLSetDifference (const In1 &a, const In2 &b)
 Implicit comparator, implicit return type.
 
template<typename In1 >
In1 STLSetDifference (const In1 &a, const In1 &b)
 
template<typename In1 , typename In2 , typename Out , typename Compare >
void STLSetUnion (const In1 &a, const In2 &b, Out *out, Compare compare)
 
template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type STLSetUnion (const In1 &a, const In2 &b, Out *out)
 
template<typename Out , typename In1 , typename In2 , typename Compare >
Out STLSetUnionAs (const In1 &a, const In2 &b, Compare compare)
 
template<typename Out , typename In1 , typename In2 >
Out STLSetUnionAs (const In1 &a, const In2 &b)
 
template<typename In1 , typename In2 , typename Compare >
In1 STLSetUnion (const In1 &a, const In2 &b, Compare compare)
 
template<typename In1 , typename In2 >
In1 STLSetUnion (const In1 &a, const In2 &b)
 
template<typename In1 >
In1 STLSetUnion (const In1 &a, const In1 &b)
 
template<typename In1 , typename In2 , typename Out , typename Compare >
void STLSetSymmetricDifference (const In1 &a, const In2 &b, Out *out, Compare compare)
 
template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type STLSetSymmetricDifference (const In1 &a, const In2 &b, Out *out)
 
template<typename Out , typename In1 , typename In2 , typename Compare >
Out STLSetSymmetricDifferenceAs (const In1 &a, const In2 &b, Compare comp)
 
template<typename Out , typename In1 , typename In2 >
Out STLSetSymmetricDifferenceAs (const In1 &a, const In2 &b)
 
template<typename In1 , typename In2 , typename Compare >
In1 STLSetSymmetricDifference (const In1 &a, const In2 &b, Compare comp)
 
template<typename In1 , typename In2 >
In1 STLSetSymmetricDifference (const In1 &a, const In2 &b)
 
template<typename In1 >
In1 STLSetSymmetricDifference (const In1 &a, const In1 &b)
 
template<typename In1 , typename In2 , typename Out , typename Compare >
void STLSetIntersection (const In1 &a, const In2 &b, Out *out, Compare compare)
 
template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type STLSetIntersection (const In1 &a, const In2 &b, Out *out)
 
template<typename Out , typename In1 , typename In2 , typename Compare >
Out STLSetIntersectionAs (const In1 &a, const In2 &b, Compare compare)
 
template<typename Out , typename In1 , typename In2 >
Out STLSetIntersectionAs (const In1 &a, const In2 &b)
 
template<typename In1 , typename In2 , typename Compare >
In1 STLSetIntersection (const In1 &a, const In2 &b, Compare compare)
 
template<typename In1 , typename In2 >
In1 STLSetIntersection (const In1 &a, const In2 &b)
 
template<typename In1 >
In1 STLSetIntersection (const In1 &a, const In1 &b)
 
template<typename In1 , typename In2 , typename Compare >
bool STLIncludes (const In1 &a, const In2 &b, Compare compare)
 
template<typename In1 , typename In2 >
bool STLIncludes (const In1 &a, const In2 &b)
 
template<typename InputIterator1 , typename InputIterator2 , typename Comp >
bool SortedRangesHaveIntersection (InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, Comp comparator)
 
template<typename InputIterator1 , typename InputIterator2 >
bool SortedRangesHaveIntersection (InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2)
 
template<typename In1 , typename In2 , typename Comp >
bool SortedContainersHaveIntersection (const In1 &in1, const In2 &in2, Comp comparator)
 
template<typename In1 , typename In2 >
bool SortedContainersHaveIntersection (const In1 &in1, const In2 &in2)
 
template<typename T >
size_t FastTypeId ()
 

Variables

class gtl::IntType ABSL_ATTRIBUTE_PACKED
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Utilities for container logging.

Todo
(user): Broaden the scope and rename to "stream_util.h"

The typical use looks like this:

LOG(INFO) << gtl::LogContainer(container);

By default, LogContainer() uses the LogShortUpTo100 policy: comma-space separation, no newlines, and with limit of 100 items.

Policies can be specified:

LOG(INFO) << gtl::LogContainer(container, gtl::LogMultiline());

The above example will print the container using newlines between elements, enclosed in [] braces.

See below for further details on policies.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IntType is a simple template class mechanism for defining "logical" integer-like class types that support many of the same functionalities as native integer types, but which prevent assignment, construction, and other operations from other similar integer-like types. Essentially, the template class IntType<IntTypeName, ValueType> (where ValueType assumes valid scalar types such as int, uint, int32_t, etc) has the additional property that it cannot be assigned to or constructed from other IntTypes or native integer types of equal or implicitly convertible type.

The class is useful for preventing mingling of integer variables with different logical roles or units. Unfortunately, C++ provides relatively good type-safety for user-defined classes but not for integer types. It is essentially up to the user to use nice variable names and comments to prevent accidental mismatches, such as confusing a user-index with a group-index or a time-in-milliseconds with a time-in-seconds. The use of typedefs are limited in that regard as they do not enforce type-safety.

USAGE --------------------------------------------------------------------—

DEFINE_INT_TYPE(IntTypeName, ValueType);
#define DEFINE_INT_TYPE(int_type_name, value_type)
Definition int_type.h:167

where: IntTypeName: is the desired (unique) name for the "logical" integer type. ValueType: is one of the integral types as defined by std::is_integral (see <type_traits>).

DISALLOWED OPERATIONS / TYPE-SAFETY ENFORCEMENT --------------------------—

Consider these definitions and variable declarations: DEFINE_INT_TYPE(GlobalDocID, int64_t); DEFINE_INT_TYPE(LocalDocID, int64_t); GlobalDocID global; LocalDocID local;

The class IntType prevents:

1) Assignments of other IntTypes with different IntTypeNames.

global = local; <-- Fails to compile!
local = global; <-- Fails to compile!
trees with all degrees equal to

2) Explicit/implicit conversion from an IntType to another IntType.

LocalDocID l(global); <-- Fails to compile!
LocalDocID l = global; <-- Fails to compile!
void GetGlobalDoc(GlobalDocID global) { }
GetGlobalDoc(global); <-- Compiles fine, types match!
GetGlobalDoc(local); <-- Fails to compile!

3) Implicit conversion from an IntType to a native integer type.

void GetGlobalDoc(int64_t global) { ...
GetGlobalDoc(global); <-- Fails to compile!
GetGlobalDoc(local); <-- Fails to compile!
void GetLocalDoc(int32_t local) { ...
GetLocalDoc(global); <-- Fails to compile!
GetLocalDoc(local); <-- Fails to compile!

SUPPORTED OPERATIONS -----------------------------------------------------—

The following operators are supported: unary: ++ (both prefix and postfix), +, -, ! (logical not), ~ (one's complement); comparison: ==, !=, <, <=, >, >=; numerical: +, -, *, /; assignment: =, +=, -=, /=, *=; stream: <<. Each operator allows the same IntTypeName and the ValueType to be used on both left- and right-hand sides.

It also supports an accessor value() returning the stored value as ValueType, and a templatized accessor value<T>() method that serves as syntactic sugar for static_cast<T>(var.value()). These accessors are useful when assigning the stored value into protocol buffer fields and using it as printf args.

The class also defines a hash functor that allows the IntType to be used as key to hashable containers such as hash_map and hash_set.

We suggest using the IntTypeIndexedContainer wrapper around google3's FixedArray and STL vector (see int-type-indexed-container.h) if an IntType is intended to be used as an index into these containers. These wrappers are indexed in a type-safe manner using IntTypes to ensure type-safety.

NB: this implementation does not attempt to abide by or enforce dimensional analysis on these scalar types.

EXAMPLES -----------------------------------------------------------------—

DEFINE_INT_TYPE(GlobalDocID, int64_t);
GlobalDocID global = 3;
std::cout << global; <-- Prints 3 to stdout.
for (GlobalDocID i(0); i < global; ++i) {
std::cout << i;
} <-- Print(ln)s 0 1 2 to stdout
DEFINE_INT_TYPE(LocalDocID, int64_t);
LocalDocID local;
std::cout << local; <-- Prints 0 to stdout it
default
initializes the value to 0.
local = 5;
local *= 2;
LocalDocID l(local);
std::cout << l + local; <-- Prints 20 to stdout.
GenericSearchRequest request;
request.set_doc_id(global.value()); <-- Uses value() to extract the value
from the IntType class.
int64_t value

REMARKS ------------------------------------------------------------------—

The following bad usage is permissible although discouraged. Essentially, it involves using the value*() accessors to extract the native integer type out of the IntType class. Keep in mind that the primary reason for the IntType class is to prevent accidental mingling of similar logical integer types – and not type casting from one type to another.

DEFINE_INT_TYPE(GlobalDocID, int64_t); DEFINE_INT_TYPE(LocalDocID, int64_t); GlobalDocID global; LocalDocID local;

global = local.value(); <– Compiles fine.

void GetGlobalDoc(GlobalDocID global) { ... GetGlobalDoc(local.value()); <– Compiles fine.

void GetGlobalDoc(int64_t global) { ... GetGlobalDoc(local.value()); <– Compiles fine.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This is a simplistic insertion-ordered map. It behaves similarly to an STL map, but only implements a small subset of the map's methods. Internally, we just keep a map and a list going in parallel.

This class provides no thread safety guarantees, beyond what you would normally see with std::list.

Iterators point into the list and should be stable in the face of mutations, except for an iterator pointing to an element that was just deleted.

This class supports heterogeneous lookups.

Typedef Documentation

◆ LogDefault

The default policy for new code.

Definition at line 168 of file container_logging.h.

◆ MapUtilKeyT

template<typename M >
using gtl::MapUtilKeyT = typename MapUtilValueT<M>::first_type

Definition at line 25 of file map_util.h.

◆ MapUtilMappedT

template<typename M >
using gtl::MapUtilMappedT = typename MapUtilValueT<M>::second_type

Definition at line 27 of file map_util.h.

◆ MapUtilValueT

template<typename M >
using gtl::MapUtilValueT = typename M::value_type

Definition at line 23 of file map_util.h.

Function Documentation

◆ ContainsKey()

template<class Collection , class Key >
bool gtl::ContainsKey ( const Collection & collection,
const Key & key )

Test to see if a std::set, std::map, std::unordered_set or std::unordered_map contains a particular key. Returns true if the key is in the collection.

Definition at line 205 of file map_util.h.

◆ FastTypeId()

template<typename T >
size_t gtl::FastTypeId ( )
inline

Definition at line 19 of file typeid.h.

◆ FindCopy()

template<class Collection , class Key , class Value >
bool gtl::FindCopy ( const Collection & collection,
const Key & key,
Value *const value )

Perform a lookup in std::map or std::unordered_map. If the key is present and value is non-NULL then a copy of the value associated with the key is made into *value. Returns whether key was present.

Definition at line 190 of file map_util.h.

◆ FindOrDie()

template<class Collection >
const Collection::value_type::second_type & gtl::FindOrDie ( const Collection & collection,
const typename Collection::value_type::first_type & key )

Definition at line 211 of file map_util.h.

◆ FindOrDieNoPrint() [1/2]

template<class Collection >
Collection::value_type::second_type & gtl::FindOrDieNoPrint ( Collection & collection,
const typename Collection::value_type::first_type & key )

Same as above, but returns a non-const reference.

Definition at line 231 of file map_util.h.

◆ FindOrDieNoPrint() [2/2]

template<class Collection >
const Collection::value_type::second_type & gtl::FindOrDieNoPrint ( const Collection & collection,
const typename Collection::value_type::first_type & key )

Same as FindOrDie above, but doesn't log the key on failure.

Definition at line 221 of file map_util.h.

◆ FindOrNull() [1/2]

template<class Collection >
Collection::value_type::second_type * gtl::FindOrNull ( Collection & collection,
const typename Collection::value_type::first_type & key )

Perform a lookup in a std::map or std::unordered_map. Same as above but the returned pointer is not const and can be used to change the stored value.

Definition at line 79 of file map_util.h.

◆ FindOrNull() [2/2]

template<class Collection >
const Collection::value_type::second_type * gtl::FindOrNull ( const Collection & collection,
const typename Collection::value_type::first_type & key )

Perform a lookup in a std::map or std::unordered_map. If the key is present a const pointer to the associated value is returned, otherwise a NULL pointer is returned.

Definition at line 65 of file map_util.h.

◆ FindPtrOrNull()

template<class Collection >
const Collection::value_type::second_type gtl::FindPtrOrNull ( const Collection & collection,
const typename Collection::value_type::first_type & key )

Perform a lookup in a std::map or std::unordered_map whose values are pointers. If the key is present a const pointer to the associated value is returned, otherwise a NULL pointer is returned. This function does not distinguish between a missing key and a key mapped to a NULL value.

Definition at line 94 of file map_util.h.

◆ FindWithDefault() [1/2]

template<class Collection , typename KeyType = MapUtilKeyT<Collection>>
const MapUtilMappedT< Collection > & gtl::FindWithDefault ( const Collection & collection,
const KeyType & key )

Returns a const reference to the value associated with the given key if it exists, otherwise returns a const reference to a value-initialized object that is never destroyed.

Definition at line 50 of file map_util.h.

◆ FindWithDefault() [2/2]

template<typename Collection , typename KeyType = MapUtilKeyT<Collection>>
const MapUtilMappedT< Collection > & gtl::FindWithDefault ( const Collection & collection,
const KeyType & key,
const MapUtilMappedT< Collection > & value )

Perform a lookup in a std::map or std::unordered_map. If the key is present in the map then the value associated with that key is returned, otherwise the value passed as a default is returned.

Prefer the two-argument form unless you need to specify a custom default value (i.e., one that is not equal to a value-initialized instance).

Definition at line 36 of file map_util.h.

◆ HashMapEquality() [1/3]

template<typename HashMap >
bool gtl::HashMapEquality ( const HashMap & a,
const HashMap & b )
inline

Definition at line 303 of file stl_util.h.

◆ HashMapEquality() [2/3]

template<typename HashMap , typename BinaryPredicate >
bool gtl::HashMapEquality ( const HashMap & map_a,
const HashMap & map_b,
BinaryPredicate mapped_type_equal )
inline
Warning
Using HashMapEquality for multiple-associative containers like multimap and hash_multimap will result in wrong behavior.

Definition at line 282 of file stl_util.h.

◆ HashMapEquality() [3/3]

template<typename K , typename V , typename C , typename A >
bool gtl::HashMapEquality ( const std::map< K, V, C, A > & map_a,
const std::map< K, V, C, A > & map_b )
inline

We overload for 'map' without a specialized functor and simply use its operator== function.

Definition at line 297 of file stl_util.h.

◆ HashSetEquality()

template<typename HashSet >
bool gtl::HashSetEquality ( const HashSet & set_a,
const HashSet & set_b )
inline

Tests two hash maps/sets for equality. This exists because operator== in the STL can return false when the maps/sets contain identical elements. This is because it compares the internal hash tables which may be different if the order of insertions and deletions differed.

Definition at line 270 of file stl_util.h.

◆ InsertIfNotPresent() [1/2]

template<class Collection , class Key , class Value >
bool gtl::InsertIfNotPresent ( Collection *const collection,
const Key & key,
const Value & value )

Insert a new key and value into a std::map or std::unordered_map. If the key is not present in the map the key and value are inserted, otherwise nothing happens. True indicates that an insert took place, false indicates the key was already present.

Definition at line 139 of file map_util.h.

◆ InsertIfNotPresent() [2/2]

template<class Collection >
bool gtl::InsertIfNotPresent ( Collection *const collection,
const typename Collection::value_type & value )

Insert a new key into a set. If the key is not present in the set the key is inserted, otherwise nothing happens. True indicates that an insert took place, false indicates the key was already present.

Definition at line 127 of file map_util.h.

◆ InsertKeyOrDie()

template<typename Collection >
auto & gtl::InsertKeyOrDie ( Collection *const collection,
const typename Collection::value_type::first_type & key )

Inserts a key into a map with the default value or dies. Returns a reference to the inserted element.

Definition at line 178 of file map_util.h.

◆ InsertOrDie() [1/2]

template<class Collection >
void gtl::InsertOrDie ( Collection *const collection,
const typename Collection::value_type & value )

Inserts a new std::pair<key,value> into a std::map or std::unordered_map. Insert a new key into a std::set or std::unordered_set. Dies if the key is already present.

Definition at line 159 of file map_util.h.

◆ InsertOrDie() [2/2]

template<class Collection >
void gtl::InsertOrDie ( Collection *const collection,
const typename Collection::value_type::first_type & key,
const typename Collection::value_type::second_type & data )

Inserts a new key/value into a std::map or std::unordered_map. Dies if the key is already present.

Definition at line 167 of file map_util.h.

◆ InsertOrDieNoPrint()

template<class Collection >
void gtl::InsertOrDieNoPrint ( Collection *const collection,
const typename Collection::value_type & value )

Inserts a new std::pair<key,value> into a std::map or std::unordered_map. Insert a new key into a std::set or std::unordered_set. Dies if the key is already present.

Definition at line 150 of file map_util.h.

◆ InsertOrUpdate()

template<class Collection , class Key , class Value >
bool gtl::InsertOrUpdate ( Collection *const collection,
const Key & key,
const Value & value )

Change the value associated with a particular key in a std::map or std::unordered_map. If the key is not present in the map the key and value are inserted, otherwise the value is updated to be a copy of the value provided. True indicates that an insert took place, false indicates an update.

update

Definition at line 110 of file map_util.h.

◆ INT_TYPE_ARITHMETIC_OP() [1/5]

gtl::INT_TYPE_ARITHMETIC_OP ( % )

◆ INT_TYPE_ARITHMETIC_OP() [2/5]

gtl::INT_TYPE_ARITHMETIC_OP ( + )

◆ INT_TYPE_ARITHMETIC_OP() [3/5]

gtl::INT_TYPE_ARITHMETIC_OP ( - )

◆ INT_TYPE_ARITHMETIC_OP() [4/5]

INT_TYPE_ARITHMETIC_OP * gtl::INT_TYPE_ARITHMETIC_OP ( / )

◆ INT_TYPE_ARITHMETIC_OP() [5/5]

gtl::INT_TYPE_ARITHMETIC_OP ( )

◆ INT_TYPE_COMPARISON_OP() [1/4]

gtl::INT_TYPE_COMPARISON_OP ( ! )

◆ INT_TYPE_COMPARISON_OP() [2/4]

gtl::INT_TYPE_COMPARISON_OP ( <= )

◆ INT_TYPE_COMPARISON_OP() [3/4]

gtl::INT_TYPE_COMPARISON_OP ( )

◆ INT_TYPE_COMPARISON_OP() [4/4]

gtl::INT_TYPE_COMPARISON_OP ( >= )

◆ LogContainer() [1/2]

template<typename ContainerT >
auto gtl::LogContainer ( const ContainerT & container) -> decltype(gtl::LogContainer(container, LogDefault()))

Log a container. For example:

LOG(INFO) << gtl::LogContainer(container);

By default, Container() uses the LogShortUpTo100 policy: comma-space separation, no newlines, and with limit of 100 items.

Definition at line 287 of file container_logging.h.

◆ LogContainer() [2/2]

template<typename ContainerT , typename PolicyT >
auto gtl::LogContainer ( const ContainerT & container,
const PolicyT & policy ) -> decltype(gtl::LogRange(container.begin(), container.end(), policy))

Log a container using "policy". For example:

LOG(INFO) << gtl::LogContainer(container, gtl::LogMultiline());

The above example will print the container using newlines between elements, enclosed in [] braces.

Definition at line 275 of file container_logging.h.

◆ LogEnum()

template<typename E >
detail::EnumLogger< E > gtl::LogEnum ( E e)

Log a (possibly scoped) enum. For example:

enum class Color { kRed, kGreen, kBlue }; LOG(INFO) << gtl::LogEnum(kRed);

Definition at line 297 of file container_logging.h.

◆ LogRange() [1/2]

template<typename IteratorT >
detail::RangeLogger< IteratorT, LogDefault > gtl::LogRange ( const IteratorT & begin,
const IteratorT & end )

Log a range. For example:

LOG(INFO) << gtl::LogRange(start_pos, end_pos);

By default, Range() uses the LogShortUpTo100 policy: comma-space separation, no newlines, and with limit of 100 items.

Definition at line 263 of file container_logging.h.

◆ LogRange() [2/2]

template<typename IteratorT , typename PolicyT >
detail::RangeLogger< IteratorT, PolicyT > gtl::LogRange ( const IteratorT & begin,
const IteratorT & end,
const PolicyT & policy )

Log a range using "policy". For example:

LOG(INFO) << gtl::LogRange(start_pos, end_pos, gtl::LogMultiline());

The above example will print the range using newlines between elements, enclosed in [] braces.

Definition at line 250 of file container_logging.h.

◆ LogRangeToStream()

template<typename IteratorT , typename PolicyT >
void gtl::LogRangeToStream ( std::ostream & out,
IteratorT begin,
IteratorT end,
const PolicyT & policy )
inline

LogRangeToStream should be used to define operator<< for STL and STL-like containers. For example, see stl_logging.h.

Definition at line 173 of file container_logging.h.

◆ LookupOrInsert()

template<class Collection >
Collection::value_type::second_type & gtl::LookupOrInsert ( Collection *const collection,
const typename Collection::value_type::first_type & key,
const typename Collection::value_type::second_type & value )

Lookup a key in a std::map or std::unordered_map, insert it if it is not present. Returns a reference to the value associated with the key.

Definition at line 242 of file map_util.h.

◆ operator<<()

template<typename IntTypeName , typename ValueType >
std::ostream & gtl::operator<< ( std::ostream & os,
IntType< IntTypeName, ValueType > arg )

– NON-MEMBER STREAM OPERATORS -------------------------------------------— We provide the << operator, primarily for logging purposes. Currently, there seems to be no need for an >> operator.

Definition at line 285 of file int_type.h.

◆ release_ptr()

template<typename T >
ABSL_MUST_USE_RESULT T * gtl::release_ptr ( T ** ptr)

Sets the referenced pointer to nullptr and returns its original value. This can be a convenient way to remove a pointer from a container to avoid the eventual deletion by an ElementDeleter.

Example:

std::vector<Foo*> v{new Foo, new Foo, new Foo}; ElementDeleter d(&v); Foo* safe = release_ptr(&v[1]); ///< v[1] is now nullptr and the Foo it previously pointed to is now ///< stored in "safe"

Definition at line 533 of file stl_util.h.

◆ reversed_view()

template<class Container >
ReverseView< Container > gtl::reversed_view ( const Container & c)

Definition at line 33 of file iterator_adaptors.h.

◆ SortedContainersHaveIntersection() [1/2]

template<typename In1 , typename In2 >
bool gtl::SortedContainersHaveIntersection ( const In1 & in1,
const In2 & in2 )

Definition at line 893 of file stl_util.h.

◆ SortedContainersHaveIntersection() [2/2]

template<typename In1 , typename In2 , typename Comp >
bool gtl::SortedContainersHaveIntersection ( const In1 & in1,
const In2 & in2,
Comp comparator )

Returns true iff the ordered containers 'in1' and 'in2' have a non-empty intersection. The container elements do not have to be the same type, but the elements must be sorted either by the specified comparator, or by '<' if no comparator is given.

Definition at line 887 of file stl_util.h.

◆ SortedRangesHaveIntersection() [1/2]

template<typename InputIterator1 , typename InputIterator2 >
bool gtl::SortedRangesHaveIntersection ( InputIterator1 begin1,
InputIterator1 end1,
InputIterator2 begin2,
InputIterator2 end2 )

Definition at line 876 of file stl_util.h.

◆ SortedRangesHaveIntersection() [2/2]

template<typename InputIterator1 , typename InputIterator2 , typename Comp >
bool gtl::SortedRangesHaveIntersection ( InputIterator1 begin1,
InputIterator1 end1,
InputIterator2 begin2,
InputIterator2 end2,
Comp comparator )

SortedRangesHaveIntersection:

bool SortedRangesHaveIntersection(begin1, end1, begin2, end2);
bool SortedRangesHaveIntersection(begin1, end1, begin2, end2,
comparator);
bool SortedRangesHaveIntersection(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, Comp comparator)
Definition stl_util.h:857

Returns true iff any element in the sorted range [begin1, end1) is equivalent to any element in the sorted range [begin2, end2). The iterators themselves do not have to be the same type, but the value types must be sorted either by the specified comparator, or by '<' if no comparator is given. [Two elements a,b are considered equivalent if !(a < b) && !(b < a) ].

Definition at line 857 of file stl_util.h.

◆ STLAppendToString()

void gtl::STLAppendToString ( std::string * str,
const char * ptr,
size_t n )
inline

Appends the n bytes starting at ptr to the given string. This is intended to be faster than string::append() in SOME cases, however, it's actually slower in some cases as well.

Just use string::append directly unless you have benchmarks showing that this function makes your code faster. (Even then, a future version of string::append() may be faster than this.)

Definition at line 239 of file stl_util.h.

◆ STLAssignToString()

void gtl::STLAssignToString ( std::string * str,
const char * ptr,
size_t n )
inline

Assigns the n bytes starting at ptr to the given string. This is intended to be faster than string::assign() in SOME cases, however, it's actually slower in some cases as well.

Just use string::assign directly unless you have benchmarks showing that this function makes your code faster. (Even then, a future version of string::assign() may be faster than this.)

Definition at line 226 of file stl_util.h.

◆ STLClearHashIfBig()

template<typename T >
void gtl::STLClearHashIfBig ( T * obj,
size_t limit )
inline

Removes all elements and reduces the number of buckets in a hash_set or hash_map back to the default if the current number of buckets is "limit" or more.

Adding items to a hash container may add buckets, but removing items or calling clear() does not necessarily reduce the number of buckets. Having lots of buckets is good if you insert comparably many items in every iteration because you'll reduce collisions and table resizes. But having lots of buckets is bad if you insert few items in most subsequent iterations, because repeatedly clearing out all those buckets can get expensive.

One solution is to call STLClearHashIfBig() with a "limit" value that is a small multiple of the typical number of items in your table. In the common case, this is equivalent to an ordinary clear. In the rare case where you insert a lot of items, the number of buckets is reset to the default to keep subsequent clear operations cheap. Note that the default number of buckets is 193 in the Gnu library implementation as of Jan '08.

Definition at line 180 of file stl_util.h.

◆ STLClearIfBig() [1/2]

template<typename T , typename A >
void gtl::STLClearIfBig ( std::deque< T, A > * obj,
size_t limit = 1 << 20 )
inline

STLClearIfBig overload for deque, which is missing capacity().

Definition at line 154 of file stl_util.h.

◆ STLClearIfBig() [2/2]

template<typename T >
void gtl::STLClearIfBig ( T * obj,
size_t limit = 1 << 20 )
inline

Calls STLClearObject() if the object is bigger than the specified limit, otherwise calls the object's clear() member. This can be useful if you want to allow the object to hold on to its allocated memory as long as it's not too much.

Note
The name is misleading since the object is always cleared, regardless of its size.

Definition at line 145 of file stl_util.h.

◆ STLClearObject() [1/2]

template<typename T , typename A >
void gtl::STLClearObject ( std::deque< T, A > * obj)

STLClearObject overload for deque, which is missing reserve().

Definition at line 132 of file stl_util.h.

◆ STLClearObject() [2/2]

template<typename T >
void gtl::STLClearObject ( T * obj)

Clears internal memory of an STL object by swapping the argument with a new, empty object. STL clear()/reserve(0) does not always free internal memory allocated.

This reserve(0) is needed because "T tmp" sometimes allocates memory (arena implementation?), even though this may not always work.

Definition at line 123 of file stl_util.h.

◆ STLDeleteContainerPairFirstPointers()

template<typename ForwardIterator >
void gtl::STLDeleteContainerPairFirstPointers ( ForwardIterator begin,
ForwardIterator end )

Calls delete (non-array version) on the FIRST item (pointer) in each pair in the range [begin, end).

Definition at line 338 of file stl_util.h.

◆ STLDeleteContainerPairPointers()

template<typename ForwardIterator >
void gtl::STLDeleteContainerPairPointers ( ForwardIterator begin,
ForwardIterator end )

Calls delete (non-array version) on BOTH items (pointers) in each pair in the range [begin, end).

Definition at line 325 of file stl_util.h.

◆ STLDeleteContainerPairSecondPointers()

template<typename ForwardIterator >
void gtl::STLDeleteContainerPairSecondPointers ( ForwardIterator begin,
ForwardIterator end )

Calls delete (non-array version) on the SECOND item (pointer) in each pair in the range [begin, end).

Note
If you're calling this on an entire container, you probably want to call STLDeleteValues(&container) instead, or use ValueDeleter.

Definition at line 353 of file stl_util.h.

◆ STLDeleteContainerPointers()

template<typename ForwardIterator >
void gtl::STLDeleteContainerPointers ( ForwardIterator begin,
ForwardIterator end )

Calls delete (non-array version) on pointers in the range [begin, end).

Note
If you're calling this on an entire container, you probably want to call STLDeleteElements(&container) instead (which also clears the container), or use an ElementDeleter.

Definition at line 314 of file stl_util.h.

◆ STLDeleteElements()

template<typename T >
void gtl::STLDeleteElements ( T * container)

Deletes all the elements in an STL container and clears the container. This function is suitable for use with a vector, set, hash_set, or any other STL container which defines sensible begin(), end(), and clear() methods.

If container is nullptr, this function is a no-op.

As an alternative to calling STLDeleteElements() directly, consider ElementDeleter (defined below), which ensures that your container's elements are deleted when the ElementDeleter goes out of scope.

Definition at line 372 of file stl_util.h.

◆ STLDeleteValues()

template<typename T >
void gtl::STLDeleteValues ( T * v)

Given an STL container consisting of (key, value) pairs, STLDeleteValues deletes all the "value" components and clears the container. Does nothing in the case it's given a nullptr.

Definition at line 382 of file stl_util.h.

◆ STLEraseAllFromSequence() [1/3]

template<typename T , typename A , typename E >
void gtl::STLEraseAllFromSequence ( std::forward_list< T, A > * c,
const E & e )

Definition at line 101 of file stl_util.h.

◆ STLEraseAllFromSequence() [2/3]

template<typename T , typename A , typename E >
void gtl::STLEraseAllFromSequence ( std::list< T, A > * c,
const E & e )

Definition at line 97 of file stl_util.h.

◆ STLEraseAllFromSequence() [3/3]

template<typename T , typename E >
void gtl::STLEraseAllFromSequence ( T * v,
const E & e )

Remove every occurrence of element e in v. See http://en.wikipedia.org/wiki/Erase-remove_idiom.

Definition at line 93 of file stl_util.h.

◆ STLEraseAllFromSequenceIf() [1/3]

template<typename T , typename A , typename P >
void gtl::STLEraseAllFromSequenceIf ( std::forward_list< T, A > * c,
P pred )

Definition at line 115 of file stl_util.h.

◆ STLEraseAllFromSequenceIf() [2/3]

template<typename T , typename A , typename P >
void gtl::STLEraseAllFromSequenceIf ( std::list< T, A > * c,
P pred )

Definition at line 111 of file stl_util.h.

◆ STLEraseAllFromSequenceIf() [3/3]

template<typename T , typename P >
void gtl::STLEraseAllFromSequenceIf ( T * v,
P pred )

Remove each element e in v satisfying pred(e).

Definition at line 107 of file stl_util.h.

◆ STLIncludes() [1/2]

template<typename In1 , typename In2 >
bool gtl::STLIncludes ( const In1 & a,
const In2 & b )

Definition at line 840 of file stl_util.h.

◆ STLIncludes() [2/2]

template<typename In1 , typename In2 , typename Compare >
bool gtl::STLIncludes ( const In1 & a,
const In2 & b,
Compare compare )

Returns true iff every element in "b" is also in "a". Both containers must be sorted by the specified comparator, or by '<' if none is given.

Definition at line 830 of file stl_util.h.

◆ STLSetDifference() [1/5]

template<typename In1 >
In1 gtl::STLSetDifference ( const In1 & a,
const In1 & b )

Definition at line 640 of file stl_util.h.

◆ STLSetDifference() [2/5]

template<typename In1 , typename In2 >
In1 gtl::STLSetDifference ( const In1 & a,
const In2 & b )

Implicit comparator, implicit return type.

Definition at line 636 of file stl_util.h.

◆ STLSetDifference() [3/5]

template<typename In1 , typename In2 , typename Compare >
In1 gtl::STLSetDifference ( const In1 & a,
const In2 & b,
Compare compare )

Explicit comparator, implicit return type.

Definition at line 631 of file stl_util.h.

◆ STLSetDifference() [4/5]

template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type gtl::STLSetDifference ( const In1 & a,
const In2 & b,
Out * out )

Append to output container, Implicit comparator.

Note
The 'enable_if' keeps this overload from participating in overload resolution if 'out' is a function pointer, gracefully forcing the 3-argument overload that treats the third argument as a comparator.

Definition at line 613 of file stl_util.h.

◆ STLSetDifference() [5/5]

template<typename In1 , typename In2 , typename Out , typename Compare >
void gtl::STLSetDifference ( const In1 & a,
const In2 & b,
Out * out,
Compare compare )

STLSetDifference:

In1 STLSetDifference(a, b, compare);
void STLSetDifference(a, b, &out);
void STLSetDifference(a, b, &out, compare);
Out STLSetDifferenceAs<Out>(a, b, compare);
int64_t b
Definition table.cc:45
int64_t a
Definition table.cc:44
void STLSetDifference(const In1 &a, const In2 &b, Out *out, Compare compare)
Definition stl_util.h:595
Out STLSetDifferenceAs(const In1 &a, const In2 &b, Compare compare)
Explicit comparator, explicit return type.
Definition stl_util.h:618

Appends the elements in "a" that are not in "b" to an output container. Optionally specify a comparator, or '<' is used by default. Both input containers must be sorted with respect to the comparator. If specified, the output container must be distinct from both "a" and "b".

If an output container pointer is not given, a container will be returned by value. The return type can be explicitly specified by calling STLSetDifferenceAs, but it defaults to the type of argument "a".

See std::set_difference() for details on how set difference is computed.

The form taking 4 arguments. All other forms call into this one. Explicit comparator, append to output container.

Definition at line 595 of file stl_util.h.

◆ STLSetDifferenceAs() [1/2]

template<typename Out , typename In1 , typename In2 >
Out gtl::STLSetDifferenceAs ( const In1 & a,
const In2 & b )

Implicit comparator, explicit return type.

Definition at line 625 of file stl_util.h.

◆ STLSetDifferenceAs() [2/2]

template<typename Out , typename In1 , typename In2 , typename Compare >
Out gtl::STLSetDifferenceAs ( const In1 & a,
const In2 & b,
Compare compare )

Explicit comparator, explicit return type.

Definition at line 618 of file stl_util.h.

◆ STLSetIntersection() [1/5]

template<typename In1 >
In1 gtl::STLSetIntersection ( const In1 & a,
const In1 & b )

Definition at line 823 of file stl_util.h.

◆ STLSetIntersection() [2/5]

template<typename In1 , typename In2 >
In1 gtl::STLSetIntersection ( const In1 & a,
const In2 & b )

Definition at line 819 of file stl_util.h.

◆ STLSetIntersection() [3/5]

template<typename In1 , typename In2 , typename Compare >
In1 gtl::STLSetIntersection ( const In1 & a,
const In2 & b,
Compare compare )

Definition at line 815 of file stl_util.h.

◆ STLSetIntersection() [4/5]

template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type gtl::STLSetIntersection ( const In1 & a,
const In2 & b,
Out * out )
Note
The 'enable_if' keeps this overload from participating in overload resolution if 'out' is a function pointer, gracefully forcing the 3-argument overload that treats the third argument as a comparator.

Definition at line 799 of file stl_util.h.

◆ STLSetIntersection() [5/5]

template<typename In1 , typename In2 , typename Out , typename Compare >
void gtl::STLSetIntersection ( const In1 & a,
const In2 & b,
Out * out,
Compare compare )

STLSetIntersection:

In1 STLSetIntersection(a, b, compare);
void STLSetIntersection(a, b, &out);
void STLSetIntersection(a, b, &out, compare);
Out STLSetIntersectionAs<Out>(a, b, compare);
Out STLSetIntersectionAs(const In1 &a, const In2 &b, Compare compare)
Definition stl_util.h:804
void STLSetIntersection(const In1 &a, const In2 &b, Out *out, Compare compare)
Definition stl_util.h:782

Appends the elements that are in both "a" and "b" to output container "out". Both input containers must be sorted with operator '<' or with "compare" if specified. "out" must be distinct from both "a" and "b".

See std::set_intersection() for how set intersection is computed.

Definition at line 782 of file stl_util.h.

◆ STLSetIntersectionAs() [1/2]

template<typename Out , typename In1 , typename In2 >
Out gtl::STLSetIntersectionAs ( const In1 & a,
const In2 & b )

Definition at line 810 of file stl_util.h.

◆ STLSetIntersectionAs() [2/2]

template<typename Out , typename In1 , typename In2 , typename Compare >
Out gtl::STLSetIntersectionAs ( const In1 & a,
const In2 & b,
Compare compare )

Definition at line 804 of file stl_util.h.

◆ STLSetSymmetricDifference() [1/5]

template<typename In1 >
In1 gtl::STLSetSymmetricDifference ( const In1 & a,
const In1 & b )

Definition at line 762 of file stl_util.h.

◆ STLSetSymmetricDifference() [2/5]

template<typename In1 , typename In2 >
In1 gtl::STLSetSymmetricDifference ( const In1 & a,
const In2 & b )

Definition at line 757 of file stl_util.h.

◆ STLSetSymmetricDifference() [3/5]

template<typename In1 , typename In2 , typename Compare >
In1 gtl::STLSetSymmetricDifference ( const In1 & a,
const In2 & b,
Compare comp )

Definition at line 753 of file stl_util.h.

◆ STLSetSymmetricDifference() [4/5]

template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type gtl::STLSetSymmetricDifference ( const In1 & a,
const In2 & b,
Out * out )
Note
The 'enable_if' keeps this overload from participating in overload resolution if 'out' is a function pointer, gracefully forcing the 3-argument overload that treats the third argument as a comparator.

Definition at line 737 of file stl_util.h.

◆ STLSetSymmetricDifference() [5/5]

template<typename In1 , typename In2 , typename Out , typename Compare >
void gtl::STLSetSymmetricDifference ( const In1 & a,
const In2 & b,
Out * out,
Compare compare )

STLSetSymmetricDifference:

In1 STLSetSymmetricDifference(a, b, compare);
void STLSetSymmetricDifference(a, b, &out, compare);
Out STLSetSymmetricDifferenceAs(const In1 &a, const In2 &b, Compare comp)
Definition stl_util.h:742
void STLSetSymmetricDifference(const In1 &a, const In2 &b, Out *out, Compare compare)
Definition stl_util.h:719

Appends the elements in "a" that are not in "b", and the elements in "b" that are not in "a", to output container "out". Both input containers must be sorted with operator '<', or with the comparator if specified. "out" must be distinct from both "a" and "b".

See std::set_symmetric_difference() for how these elements are selected.

Definition at line 719 of file stl_util.h.

◆ STLSetSymmetricDifferenceAs() [1/2]

template<typename Out , typename In1 , typename In2 >
Out gtl::STLSetSymmetricDifferenceAs ( const In1 & a,
const In2 & b )

Definition at line 748 of file stl_util.h.

◆ STLSetSymmetricDifferenceAs() [2/2]

template<typename Out , typename In1 , typename In2 , typename Compare >
Out gtl::STLSetSymmetricDifferenceAs ( const In1 & a,
const In2 & b,
Compare comp )

Definition at line 742 of file stl_util.h.

◆ STLSetUnion() [1/5]

template<typename In1 >
In1 gtl::STLSetUnion ( const In1 & a,
const In1 & b )

Definition at line 699 of file stl_util.h.

◆ STLSetUnion() [2/5]

template<typename In1 , typename In2 >
In1 gtl::STLSetUnion ( const In1 & a,
const In2 & b )

Definition at line 695 of file stl_util.h.

◆ STLSetUnion() [3/5]

template<typename In1 , typename In2 , typename Compare >
In1 gtl::STLSetUnion ( const In1 & a,
const In2 & b,
Compare compare )

Definition at line 691 of file stl_util.h.

◆ STLSetUnion() [4/5]

template<typename In1 , typename In2 , typename Out >
std::enable_if<!std::is_function< Out >::value, void >::type gtl::STLSetUnion ( const In1 & a,
const In2 & b,
Out * out )
Note
The 'enable_if' keeps this overload from participating in overload resolution if 'out' is a function pointer, gracefully forcing the 3-argument overload that treats the third argument as a comparator.

Definition at line 676 of file stl_util.h.

◆ STLSetUnion() [5/5]

template<typename In1 , typename In2 , typename Out , typename Compare >
void gtl::STLSetUnion ( const In1 & a,
const In2 & b,
Out * out,
Compare compare )

STLSetUnion:

In1 STLSetUnion(a, b);
In1 STLSetUnion(a, b, compare);
void STLSetUnion(a, b, &out);
void STLSetUnion(a, b, &out, compare);
Out STLSetUnionAs<Out>(a, b, compare);
void STLSetUnion(const In1 &a, const In2 &b, Out *out, Compare compare)
Definition stl_util.h:660
Out STLSetUnionAs(const In1 &a, const In2 &b, Compare compare)
Definition stl_util.h:681

Appends the elements in one or both of the input containers to output container "out". Both input containers must be sorted with operator '<', or with the comparator if specified. "out" must be distinct from both "a" and "b".

See std::set_union() for how set union is computed.

Definition at line 660 of file stl_util.h.

◆ STLSetUnionAs() [1/2]

template<typename Out , typename In1 , typename In2 >
Out gtl::STLSetUnionAs ( const In1 & a,
const In2 & b )

Definition at line 687 of file stl_util.h.

◆ STLSetUnionAs() [2/2]

template<typename Out , typename In1 , typename In2 , typename Compare >
Out gtl::STLSetUnionAs ( const In1 & a,
const In2 & b,
Compare compare )

Definition at line 681 of file stl_util.h.

◆ STLSortAndRemoveDuplicates() [1/2]

template<typename T >
void gtl::STLSortAndRemoveDuplicates ( T * v)
inline

Definition at line 65 of file stl_util.h.

◆ STLSortAndRemoveDuplicates() [2/2]

template<typename T , typename LessFunc >
void gtl::STLSortAndRemoveDuplicates ( T * v,
const LessFunc & less_func )
inline

Sorts and removes duplicates from a sequence container. If specified, the 'less_func' is used to compose an equivalence comparator for the sorting and uniqueness tests.

Definition at line 58 of file stl_util.h.

◆ STLStableSortAndRemoveDuplicates() [1/2]

template<typename T >
void gtl::STLStableSortAndRemoveDuplicates ( T * v)
inline

Stable sorts and removes duplicates from a sequence container, retaining the first equivalent element for each equivalence set, using < comparison and == equivalence testing.

Definition at line 85 of file stl_util.h.

◆ STLStableSortAndRemoveDuplicates() [2/2]

template<typename T , typename LessFunc >
void gtl::STLStableSortAndRemoveDuplicates ( T * v,
const LessFunc & less_func )
inline

Stable sorts and removes duplicates from a sequence container, retaining the first equivalent element for each equivalence set. The 'less_func' is used to compose an equivalence comparator for the sorting and uniqueness tests.

Definition at line 75 of file stl_util.h.

◆ STLStringReserveIfNeeded()

void gtl::STLStringReserveIfNeeded ( std::string * s,
size_t min_capacity )
inline

Reserves space in the given string only if the existing capacity is not already enough. This is useful for strings because string::reserve() may shrink the capacity in some cases, which is usually not what users want. The behavior of this function is similar to that of vector::reserve() but for string.

Definition at line 194 of file stl_util.h.

◆ STLStringResizeUninitialized()

template<typename T , typename Traits , typename Alloc >
void gtl::STLStringResizeUninitialized ( std::basic_string< T, Traits, Alloc > * s,
size_t new_size )
inline

Like str->resize(new_size), except any new characters added to "*str" as a result of resizing may be left uninitialized, rather than being filled with '0' bytes. Typically used when code is then going to overwrite the backing store of the string with known data.

Definition at line 203 of file stl_util.h.

◆ STLStringSupportsNontrashingResize()

template<typename T , typename Traits , typename Alloc >
bool gtl::STLStringSupportsNontrashingResize ( const std::basic_string< T, Traits, Alloc > & s)
inline

Returns true if the string implementation supports a resize where the new characters added to the string are left untouched.

(A better name might be "STLStringSupportsUninitializedResize", alluding to the previous function.)

Definition at line 214 of file stl_util.h.

◆ string_as_array()

char * gtl::string_as_array ( std::string * str)
inline

Returns a mutable char* pointing to a string's internal buffer, which may not be null-terminated. Returns nullptr for an empty string. If not non-null, writing through this pointer will modify the string.

string_as_array(&str)[i] is valid for 0 <= i < str.size() until the next call to a string method that invalidates iterators.

In C++11 you may simply use &str[0] to get a mutable char*.

Prior to C++11, there was no standard-blessed way of getting a mutable reference to a string's internal buffer. The requirement that string be contiguous is officially part of the C++11 standard [string.require]/5. According to Matt Austern, this should already work on all current C++98 implementations.

DO NOT USE const_cast<char*>(str->data())! See the unittest for why.

Definition at line 260 of file stl_util.h.

Variable Documentation

◆ ABSL_ATTRIBUTE_PACKED

class gtl::IntType gtl::ABSL_ATTRIBUTE_PACKED