MySQL  8.0.15
Source Code Documentation
map_helpers.h File Reference
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "m_ctype.h"
#include "my_inttypes.h"
#include "sql/malloc_allocator.h"
#include "sql/memroot_allocator.h"
#include "template_utils.h"

Go to the source code of this file.

Classes

struct  My_free_deleter
 
struct  Free_deleter
 
class  Collation_hasher
 A Hasher that hashes std::strings according to a MySQL collation. More...
 
class  Collation_key_equal
 A KeyEqual that compares std::strings according to a MySQL collation. More...
 
class  malloc_unordered_map< Key, Value, Hash, KeyEqual >
 std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  malloc_unordered_set< Key, Hash, KeyEqual >
 std::unordered_set, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  malloc_unordered_multimap< Key, Value, Hash, KeyEqual >
 std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  collation_unordered_map< Key, Value >
 std::unordered_map, but with my_malloc and collation-aware comparison. More...
 
class  collation_unordered_multimap< Key, Value >
 std::unordered_multimap, but with my_malloc and collation-aware comparison. More...
 
class  collation_unordered_set< Key >
 std::unordered_set, but with my_malloc and collation-aware comparison. More...
 
class  memroot_unordered_set< Key, Hash, KeyEqual >
 std::unordered_set, but allocated on a MEM_ROOT. More...
 

Typedefs

template<class T >
using unique_ptr_with_deleter = std::unique_ptr< T, void(*)(T *)>
 std::unique_ptr, but with a custom delete function. More...
 
template<class T >
using unique_ptr_my_free = std::unique_ptr< T, My_free_deleter >
 std::unique_ptr, but with my_free as deleter. More...
 
template<class T >
using unique_ptr_free = std::unique_ptr< T, Free_deleter >
 std::unique_ptr, but with free as deleter. More...
 

Functions

template<class Container , class Key >
static auto find_or_nullptr (const Container &container, const Key &key) -> typename std::enable_if< std::is_pointer< typename Container::value_type::second_type >::value, typename Container::value_type::second_type >::type
 Some useful helpers for associative arrays with MySQL-specific semantics. More...
 
template<class Container >
Container::iterator erase_specific_element (Container *container, const typename Container::key_type &key, const typename Container::value_type::second_type &value)
 For unordered_multimap<Key, Value>, erase the first specific element that matches both the given key and value. More...
 
template<class Container >
static auto erase_specific_element (Container *container, const typename Container::key_type &key, typename Container::value_type::second_type::pointer value) -> typename std::enable_if< std::is_pointer< typename Container::value_type::second_type::pointer >::value, typename Container::iterator >::type
 Same as regular erase_specific_element(), but for the case where the container holds unique_ptr elements. More...
 

Typedef Documentation

◆ unique_ptr_free

template<class T >
using unique_ptr_free = std::unique_ptr<T, Free_deleter>

std::unique_ptr, but with free as deleter.

◆ unique_ptr_my_free

template<class T >
using unique_ptr_my_free = std::unique_ptr<T, My_free_deleter>

std::unique_ptr, but with my_free as deleter.

◆ unique_ptr_with_deleter

template<class T >
using unique_ptr_with_deleter = std::unique_ptr<T, void (*)(T *)>

std::unique_ptr, but with a custom delete function.

Normally, it is more efficient to have a deleter class instead, but this allows you to have a unique_ptr to a forward-declared class, so it keeps include dependencies down somewhat.

Function Documentation

◆ erase_specific_element() [1/2]

template<class Container >
Container::iterator erase_specific_element ( Container *  container,
const typename Container::key_type key,
const typename Container::value_type::second_type &  value 
)

For unordered_multimap<Key, Value>, erase the first specific element that matches both the given key and value.

◆ erase_specific_element() [2/2]

template<class Container >
static auto erase_specific_element ( Container *  container,
const typename Container::key_type key,
typename Container::value_type::second_type::pointer  value 
) -> typename std::enable_if< std::is_pointer< typename Container::value_type::second_type::pointer>::value, typename Container::iterator>::type
inlinestatic

Same as regular erase_specific_element(), but for the case where the container holds unique_ptr elements.

◆ find_or_nullptr()

template<class Container , class Key >
static auto find_or_nullptr ( const Container &  container,
const Key &  key 
) -> typename std::enable_if< std::is_pointer<typename Container::value_type::second_type>::value, typename Container::value_type::second_type>::type
inlinestatic

Some useful helpers for associative arrays with MySQL-specific semantics.

For unordered_map<Key, T*> or unordered_map<Key, unique_ptr<T>>, does find() and returns nullptr if the element was not found.

It is not possible to distinguish between "not found" and "found, but contained nullptr" in this case. Thus, you should normally prefer checking against container.end() yourself.