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

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

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.
  • ```

    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.

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

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.
  • ```

Definition at line 154 of file vtkStringToken.h.