From 6e040fa87c4542ede1c61ec00c762f3c24cd7f74 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 24 Sep 2020 00:09:45 +0200 Subject: [PATCH] doc: more on hashed strings (close #559) --- docs/md/core.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/md/core.md b/docs/md/core.md index 3b22a48ec..5bfdb3ca3 100644 --- a/docs/md/core.md +++ b/docs/md/core.md @@ -115,7 +115,8 @@ human-readable identifiers in the codebase while using their numeric counterparts at runtime, thus without affecting performance.
The class has an implicit `constexpr` constructor that chews a bunch of characters. Once created, all what one can do with it is getting back the -original string or converting it into a number.
+original string through the `data` member function or converting the instance +into a number.
The good part is that a hashed string can be used wherever a constant expression is required and no _string-to-number_ conversion will take place at runtime if used carefully. @@ -137,6 +138,19 @@ more user-friendly: constexpr auto str = "text"_hs; ``` +Finally, in case users need to create hashed strings at runtime, this class also +offers the necessary functionalities: + +``` +std::string orig{"text"}; + +// create a full-featured hashed string... +entt::hashed_string str{orig.c_str()}; + +// ... or compute only the unique identifier +const auto hash = entt::hashed_string::value(orig.c_str()); +``` + ## Wide characters The hashed string has a design that is close to that of an `std::basic_string`.