ai::details Namespace Reference
String Literal Class -------------------- Replacement for: const char* const kWidgetId = "SomeMagicString";.
More...
Functions |
constexpr bool | compare_less (const char *str1, std::size_t len1, const char *str2, std::size_t len2) AINOEXCEPT |
constexpr bool | compare_equal (const char *str1, std::size_t len1, const char *str2, std::size_t len2) AINOEXCEPT |
Detailed Description
String Literal Class -------------------- Replacement for: const char* const kWidgetId = "SomeMagicString";.
How to create: constexpr ai::LiteralString kWidgetId {"WidgetName"}; constexpr ai::LiteralString kWidgetId = "WidgetName";
When to use: To specify placeholders for magic strings for which we generally use const char* const ...
Why to use:
- When a constexpr object is created with a string literal which is a constant expression (e.g. magic strings), there is:
- No runtime overhead for creation
- Size is known at compile time
- Implicit conversion to const char* when you need to call a function that expects const char*
NOTE:
- You can compare two constexpr ai::LiteralString at compile time.
- However, you can compare LiteralString with const char* with std::strcmp only at runtime.
Function Documentation
constexpr bool ai::details::compare_equal |
( |
const char * |
str1, |
|
|
std::size_t |
len1, |
|
|
const char * |
str2, |
|
|
std::size_t |
len2 | |
|
) |
| | |
constexpr bool ai::details::compare_less |
( |
const char * |
str1, |
|
|
std::size_t |
len1, |
|
|
const char * |
str2, |
|
|
std::size_t |
len2 | |
|
) |
| | |