xentara-utils v2.0.3
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator > Class Template Reference

A string that enables heterogeneous lookup when used as a key for hash tables. More...

#include <xentara/utils/string/HashKey.hpp>

+ Inheritance diagram for xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >:

Public Member Functions

constexpr BasicHashKey (const std::basic_string< Char, CharTraits, Allocator > &string)
 Conversion constructor from a regular string.
 
constexpr BasicHashKey (std::basic_string< Char, CharTraits, Allocator > &&string) noexcept
 Move-constructor from a regular string.
 
constexpr auto operator= (const std::basic_string< Char, CharTraits, Allocator > &string) -> BasicHashKey &
 Assignment operator for a regular string.
 
constexpr auto operator= (std::basic_string< Char, CharTraits, Allocator > &&string) noexcept -> BasicHashKey &
 Move-assignment operator for a regular string.
 
template<typename StringViewLike >
requires (std::is_convertible_v<const StringViewLike &, std::basic_string_view<Char, CharTraits>> && !std::is_convertible_v<const StringViewLike &, const Char *>)
constexpr BasicHashKey (const StringViewLike &string, const Allocator &alloc=Allocator())
 Make this type implicitly constructible from string view-like types.
 
- Public Member Functions inherited from std::basic_string
T append (T... args)
 
T assign (T... args)
 
T at (T... args)
 
T back (T... args)
 
T basic_string (T... args)
 
T begin (T... args)
 
T c_str (T... args)
 
T capacity (T... args)
 
T cbegin (T... args)
 
T cend (T... args)
 
T clear (T... args)
 
T compare (T... args)
 
T copy (T... args)
 
T crbegin (T... args)
 
T crend (T... args)
 
T data (T... args)
 
T empty (T... args)
 
T end (T... args)
 
T ends_with (T... args)
 
T erase (T... args)
 
T find (T... args)
 
T find_first_not_of (T... args)
 
T find_first_of (T... args)
 
T find_last_not_of (T... args)
 
T find_last_of (T... args)
 
T front (T... args)
 
T get_allocator (T... args)
 
T insert (T... args)
 
T length (T... args)
 
T max_size (T... args)
 
T operator basic_string_view (T... args)
 
T operator+= (T... args)
 
T operator= (T... args)
 
T operator[] (T... args)
 
T pop_back (T... args)
 
T push_back (T... args)
 
T rbegin (T... args)
 
T rend (T... args)
 
T replace (T... args)
 
T reserve (T... args)
 
T resize (T... args)
 
T rfind (T... args)
 
T shrink_to_fit (T... args)
 
T size (T... args)
 
T starts_with (T... args)
 
T substr (T... args)
 
T swap (T... args)
 

Detailed Description

template<typename Char, typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
class xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >

A string that enables heterogeneous lookup when used as a key for hash tables.

This class can be used as a key for std::unordered_map and std::unordered_set to enable heterogeneous lookup, allowing you to look up an entry in a hash table using any type convertible to std::basic_string_view as lookup key, not just BasicHashKey. This saves you from having to construct a string just to perform a lookup, which can lead to unwanted heap allocations. To accomplish this, this class does two things:

  1. std::hash<xentara::utils::string::BasicHashKey "std::hash<BasicHashKey>" is a transparent hash, allowing any object convertible to std::basic_string_view to be hashed.
  2. BasicHashKey is implicitly constructible from any object convertible to std::basic_string_view. This is necessary for functions like std::unordered_map::try_emplace() to function correctly.

Constructor & Destructor Documentation

◆ BasicHashKey() [1/3]

template<typename Char , typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
constexpr xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >::BasicHashKey ( const std::basic_string< Char, CharTraits, Allocator > &  string)
constexpr

Conversion constructor from a regular string.

◆ BasicHashKey() [2/3]

template<typename Char , typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
constexpr xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >::BasicHashKey ( std::basic_string< Char, CharTraits, Allocator > &&  string)
constexprnoexcept

Move-constructor from a regular string.

◆ BasicHashKey() [3/3]

template<typename Char , typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
template<typename StringViewLike >
requires (std::is_convertible_v<const StringViewLike &, std::basic_string_view<Char, CharTraits>> && !std::is_convertible_v<const StringViewLike &, const Char *>)
constexpr xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >::BasicHashKey ( const StringViewLike &  string,
const Allocator &  alloc = Allocator() 
)
constexpr

Make this type implicitly constructible from string view-like types.

Member Function Documentation

◆ operator=() [1/2]

template<typename Char , typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
constexpr auto xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >::operator= ( const std::basic_string< Char, CharTraits, Allocator > &  string) -> BasicHashKey &
constexpr

Assignment operator for a regular string.

◆ operator=() [2/2]

template<typename Char , typename CharTraits = std::char_traits<Char>, typename Allocator = std::allocator<Char>>
constexpr auto xentara::utils::string::BasicHashKey< Char, CharTraits, Allocator >::operator= ( std::basic_string< Char, CharTraits, Allocator > &&  string) -> BasicHashKey &
constexprnoexcept

Move-assignment operator for a regular string.