@@ -1159,17 +1159,30 @@ namespace hud
11591159 }
11601160
11611161 /* *
1162- * Finds or inserts a slot corresponding to the given key.
1163- * If the key is not found, a new slot is created by constructing it with the key followed by `args`.
1164- * If the `key_type` is not hashable with the `key_tuple_t` a temporary key is created to find it in the hashmap
1165- * To make the `key_type` hashable with the `key_tuple_t` you must specialize the `hud::equal<key_type>` functor by adding the function
1166- * @param key The key used to find or insert the slot.
1167- * @param args The arguments forwarded to the `slot_type` constructor after the key.
1168- * @return An iterator to the inserted or existing value.
1162+ * Adds a new element to the container using piecewise construction of the key and value.
1163+ *
1164+ * If an element with the given key already exists, returns an iterator to it.
1165+ * Otherwise, constructs a new element in-place using the provided key and value tuples.
1166+ *
1167+ * The key can be provided either as a fully constructed `key_type` or as a tuple of arguments
1168+ * used to construct the key in-place. If the key tuple can't be used directly (e.g., it's not
1169+ * hashable or comparable), it must be convertible into a valid `key_type`.
1170+ *
1171+ * To enable custom key lookup using a tuple of arguments, you can specialize the `hud::equal<key_type>`
1172+ * and `hud::hash<key_type>` functors to support comparisons and hashes against a forwarding tuple
1173+ * (i.e., `hud::tuple<Args&&...>&&`).
1174+ *
1175+ * @param key_tuple Tuple of arguments used to identify or construct the key.
1176+ * @param value_tuple Tuple of arguments used to construct the associated value.
1177+ * @return An iterator to the existing or newly inserted element.
11691178 */
11701179 template <typename key_tuple_t , typename value_tuple_t >
11711180 constexpr iterator add (hud::tag_piecewise_construct_t , key_tuple_t &&key_tuple, value_tuple_t &&value_tuple) noexcept
11721181 {
1182+ /* *
1183+ * If the tuple can't be used directly as a hashable/comparable key,
1184+ * we unpack its elements and construct a key_type from them.
1185+ */
11731186 constexpr auto forward_key = []<usize... indices_key>(
11741187 key_tuple_t &&key_tuple,
11751188 hud::index_sequence<indices_key...>
@@ -1181,6 +1194,8 @@ namespace hud
11811194 }
11821195 else
11831196 {
1197+ static_assert (hud::is_constructible_v<key_type, decltype (hud::get<indices_key>(key_tuple))...>, " key_type is neither hashable nor comparable with the given tuple, and cannot be constructed from its values. "
1198+ " Ensure that hud::equal and hud::hash support hud::tuple<...&&>&&, or provide a constructor for key_type that accepts the tuple elements." );
11841199 return key_type (hud::get<indices_key>(key_tuple)...);
11851200 }
11861201 };
0 commit comments