VTK  9.4.20241108
Functions
vtk::literals Namespace Reference

Functions

constexpr VTKCOMMONCORE_EXPORT vtkStringToken::Hash operator""_hash (const char *data, std::size_t size)
 Construct the hash of a string literal, like so:
 
constexpr VTKCOMMONCORE_EXPORT vtkStringToken operator""_token (const char *data, std::size_t size)
 Construct a token from a string literal, like so:
 

Function Documentation

◆ operator""_hash()

constexpr VTKCOMMONCORE_EXPORT vtkStringToken::Hash vtk::literals::operator""_hash ( const char *  data,
std::size_t  size 
)
inlineconstexpr

Construct the hash of a string literal, like so:

++
using namespace vtk::literals;
vtkStringToken::Hash t = "test"_hash;
bool ok = false;
switch (t)
{
case "foo"_hash: ok = false;
case "test"_hash: ok = true;
}
std::cout << t << "\n"; // Prints a hash-code.
std::cout << ok << "\n"; // Prints a true value.
std::uint32_t Hash

As the example above shows, it is possible to use hashed strings in switch statements since the hashing occurs at build time. This is more efficient than a sequence of if-conditionals performing string comparisons.

Definition at line 206 of file vtkStringToken.h.

◆ operator""_token()

constexpr VTKCOMMONCORE_EXPORT vtkStringToken vtk::literals::operator""_token ( const char *  data,
std::size_t  size 
)
inlineconstexpr

Construct a token from a string literal, like so:

++
using namespace vtk::literals;
vtkStringToken t = "test"_token;
std::cout << t.id() << "\n"; // Prints a hash-code.
// std::cout << t.value() << "\n"; // Prints "test" if someone else constructed the token from a
ctor; else throws exception.
Represent a string by its integer hash.

Definition at line 226 of file vtkStringToken.h.