VTK: vtk::literals Namespace Reference

| VTK 9.3.1

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: More...
constexpr VTKCOMMONCORE_EXPORT vtkStringToken | operator""_token (const char *data, std::size_t size)
| Construct a token from a string literal, like so: More...

## 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:

{c++}
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.
vtkStringToken::Hash
std::uint32_t Hash
Definition: vtkStringToken.h:36
vtk::literals
Definition: vtkStringToken.h:116

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 139 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:

{c++}
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.
vtkStringToken
Represent a string by its integer hash.
Definition: vtkStringToken.h:34

Definition at line 154 of file vtkStringToken.h.