Other small helper utilities.
More...
|
file | uuid.h |
| Universally Unique Identifier (UUID) support.
|
|
bool | qb::likely (bool expr) |
| Hint for branch prediction when a condition is expected to be true.
|
bool | qb::unlikely (bool expr) |
| Hint for branch prediction when a condition is expected to be false.
|
template<typename... Types> |
size_t | qb::hash_combine (const Types &...args) |
| Combines the hash values of multiple objects into a single hash value.
|
template<typename T> |
std::remove_reference_t< T > && | mv (T &&t) noexcept |
| Alias for std::move with a concise syntax.
|
template<typename T> |
T && | fwd (std::remove_reference_t< T > &t) noexcept |
| Alias for std::forward with a concise syntax (lvalue overload).
|
template<typename T> |
T && | fwd (std::remove_reference_t< T > &&t) noexcept |
| Alias for std::forward with a concise syntax (rvalue overload).
|
Other small helper utilities.
Includes `qb::nocopy`, `qb::functional`, branch prediction hints, etc.
◆ likely()
bool qb::likely |
( |
bool | expr | ) |
|
|
inline |
Hint for branch prediction when a condition is expected to be true.
- Parameters
-
expr | Boolean expression to evaluate. |
- Returns
- The result of evaluating expr.
Use this function to indicate to the compiler that the expression expr is expected to evaluate to true most of the time. This can help the compiler optimize code paths that are frequently taken, potentially improving performance by reducing branch mispredictions. Typically implemented using __builtin_expect on GCC/Clang.
} else {
}
bool likely(bool expr)
Hint for branch prediction when a condition is expected to be true.
Definition branch_hints.h:49
◆ unlikely()
bool qb::unlikely |
( |
bool | expr | ) |
|
|
inline |
Hint for branch prediction when a condition is expected to be false.
- Parameters
-
expr | Boolean expression to evaluate. |
- Returns
- The result of evaluating expr.
Use this function to indicate to the compiler that the expression expr is expected to evaluate to false most of the time. This can help the compiler optimize for the more common case where the branch is not taken, or the alternative path is taken. Typically implemented using __builtin_expect on GCC/Clang.
} else {
}
bool unlikely(bool expr)
Hint for branch prediction when a condition is expected to be false.
Definition branch_hints.h:76
◆ hash_combine()
template<typename... Types>
size_t qb::hash_combine |
( |
const Types &... | args | ) |
|
Combines the hash values of multiple objects into a single hash value.
- Template Parameters
-
Types | Variadic template parameter pack of the types of objects to hash. |
- Parameters
-
args | The values whose hash codes are to be combined. |
- Returns
- A single size_t hash value representing the combination of all input values.
This function is particularly useful for creating custom hash functions for composite objects (structs or classes) to be used as keys in hash-based containers like qb::unordered_map or std::unordered_map. It iteratively combines the hash of each argument into a seed.
struct MyKey {
int id;
std::string name;
double value;
bool operator==(const MyKey& other) const {
return id == other.id && name == other.name && value == other.value;
}
};
namespace std {
template <>
struct hash<MyKey> {
std::size_t operator()(const MyKey& k) const {
}
};
}
size_t hash_combine(const Types &...args)
Combines the hash values of multiple objects into a single hash value.
Definition functional.h:83
◆ mv()
template<typename T>
std::remove_reference_t< T > && mv |
( |
T && | t | ) |
|
|
inlinenoexcept |
Alias for std::move with a concise syntax.
- Template Parameters
-
T | Type of the value to move. |
- Parameters
-
- Returns
- Value cast to an rvalue reference (std::remove_reference_t<T>&&).
◆ fwd() [1/2]
template<typename T>
T && fwd |
( |
std::remove_reference_t< T > & | t | ) |
|
|
inlinenoexcept |
Alias for std::forward with a concise syntax (lvalue overload).
- Template Parameters
-
- Parameters
-
t | Lvalue reference to forward. |
- Returns
- Forwarded reference, preserving value category and const/volatile qualifiers of T.
◆ fwd() [2/2]
template<typename T>
T && fwd |
( |
std::remove_reference_t< T > && | t | ) |
|
|
inlinenoexcept |
Alias for std::forward with a concise syntax (rvalue overload).
- Template Parameters
-
- Parameters
-
t | Rvalue reference to forward. |
- Returns
- Forwarded reference, preserving value category and const/volatile qualifiers of T.